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

安稳与你 提交于 2019-12-09 02:44:37

问题


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?


回答1:


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.




回答2:


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.




回答3:


Sure, the parser has to do more work so it will be somewhat slower. In our project we used a PHP accelerator which did result in noticeable speed improvements. I'd recommend using an accelerator and then you can comment your code and not worry about performance.




回答4:


The situation you described will not make it any slower in any significant way. The parser will see /* or // and simply skip to the next */ or newline respectively. However, if you have 50k lines of comments or something silly like that, it may slow the parser a little whilst it skips over them.

If you're looking for a way to speed things up, APC and memcached are great solutions.




回答5:


i dont think so, maybe its 0.00001 slower but dont think this is the problem if your website loads slowly :P the parser will just ignore the comments :) he's smart!



来源:https://stackoverflow.com/questions/8244369/will-php-be-slower-if-we-add-too-many-comments-in-code-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!