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?
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.
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.
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.
1 Answer. No, comments do not increase the execution time.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With