注释会使代码运行速度变慢吗? [英] Do comments make the code run slower?

查看:371
本文介绍了注释会使代码运行速度变慢吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说被评论严重的脚本比未评论的脚本运行速度稍慢。

I heard that a heavily commented script runs slightly slower than a non-commented one. Is it true?

有人测试过吗? (例如百分比变慢了多少)

Did anyone test this? (like how much slower is it in percentages)

推荐答案

注释在正常情况下不会影响脚本的执行时间。但是,您在代码中编写的行数会影响解析器以对其进行大量读取和缓冲。如果您可以在20行中执行某些操作,则尝试在1000行中编写相同的操作,如果它是按顺序执行的应用程序的一部分,则性能可能会受到影响。即使很少或多行,依存关系也很重要。如果您使用的库在很大程度上取决于某些应用程序,则显然加载时间,解析时间以及编译和执行时间等将会增加。无论如何,评论不会有太大的影响,但是几微秒不会花费您太多钱。因此,继续注释您的代码,并使其可以被联合开发人员读取。

Commenting will not affect the script execution time in normal case. But the number of lines you write in your code affect the parser to read and buffer it considerably. If you can execute certain things in 20 lines, you try to write the same thing in 1000 lines, the performance might be affecting if its part of an application which executes sequentially. Even if few lines or lot of lines the dependencies are important. If you are using a library which is heavily depending on some applications, obviously the loading time, parsing time and compile and execution time etc will increase. In any case the commenting will not affect considerably, but a few microseconds will not cost you much. So go ahead and comment your code and make it readable by co-developers.

这篇关于注释会使代码运行速度变慢吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆