Possible Duplicate:
Do comments slow down an interpreted language?
Will there be noticeable performance degradation in the execution of a large .py file if more than 75% of the lines of code are properly commented?
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.
The biggest effect that comments have is to bloat the file size and thereby slow down the download of the script.
No, comments are ignored by compile so they cannot affect the time execution.
So no, comments do not slow down the programs at run-time. Note: Interpreters that do not use some other inner structure to represent the code other than text, ie a syntax tree, must do exactly what you mentioned.
No
When you run python, the first step is to convert to bytecode, which is what those .pyc
files are. Comments are removed from these, so it won't matter*.
If you run with the -O
or -OO
option, python will produce "optimized" pyo
files, which are negligibly faster, if faster at all. The main difference is that:
-O
assertion are removed,-OO
option, the __doc__
strings are stripped out. Given that those are sometimes needed, running with -OO
isn't recommended. * it's been pointed out below that .pyc
files are only saved for modules. Thus the top-level executable must be recompiled every time it's run. This step could slow down a massive python executable. In practice, most of the code should reside in modules, making this a non-issue.
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