Skip to content
Advertisement

Do comments make the code run slower?

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)

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement