Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will PHP be slower if we add too many comments in code files? [duplicate]

Possible Duplicate:
Commenting interpreted code and performance
Does comments affect when including files in PHP?

Let's say we have 100 class files and everytime when a page is requested, all these classes must be parsed by PHP.

Will PHP be slower if almost 1 half of the source code lines are the comments? Because usually I add a lot of comments & descriptions to code. This doesn't matter to compilers coz comments are not compiled, but PHP is interpreter, any bad thing may happen?

like image 273
jondinham Avatar asked Nov 23 '11 15:11

jondinham


People also ask

Can too many comments slow down your 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.

Do code comments affect performance?

It can prevent functions from being inlined, which affects performance, though this shouldn't really happen. Show activity on this post. In some perhaps isolated circumstances, comments definitely somehow bog down the code execution.

Do comments affect runtime?

Since comments have no impact on the runtime results, they are sometimes neglected when the source code is updated.


2 Answers

Yes, but it's minimal, and this can (and should) be addressed entirely by using APC or another opcode cache. As a bonus, APC will speed everything else up as well.

If your site is slow, comments are not the reason.

like image 146
ceejayoz Avatar answered Oct 13 '22 21:10

ceejayoz


The only way it is slower, is that the interpreter has to read more bytes. But as for execution speed, it has no influence, because they are just ignored by the interpreter.

So basically, it does not matter if you add comments.

like image 21
Ikke Avatar answered Oct 13 '22 22:10

Ikke