Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do comments slow down an interpreted language?

I am asking this because I use Python, but it could apply to other interpreted languages as well (Ruby, PHP, JavaScript).

Am I slowing down the interpreter whenever I leave a comment in my code? According to my limited understanding of an interpreter, it reads program expressions in as strings and then converts those strings into code. It seems that every time it parses a comment, that is wasted time.

Is this the case? Is there some convention for comments in interpreted languages, or is the effect negligible?

like image 757
Mantas Vidutis Avatar asked Apr 28 '10 15:04

Mantas Vidutis


People also ask

Do adding comments slow down code?

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.

Does comments affect code performance?

No it does not effect performance. As most of the programming languages compile or interpret code and comments are skipped as computer has nothing to do with comments.

Do comments slow down JavaScript?

Whitespaces and comments increase the size of the JavaScript file, which slows down the actual downloading of the file from the server - minification is the process of stripping unnecessary characters from a JavaScript file to make it smaller and easier to download.

Do comments increase execution time?

1 Answer. No, comments do not increase the execution time.


1 Answers

For the case of Python, source files are compiled before being executed (the .pyc files), and the comments are stripped in the process. So comments could slow down the compilation time if you have gazillions of them, but they won't impact the execution time.

like image 120
Luper Rouch Avatar answered Sep 24 '22 02:09

Luper Rouch