By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,882 Members | 2,460 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,882 IT Pros & Developers. It's quick & easy.

Comments, do they technicaly slow php down?

P: n/a
Hi,

I proud myself in having good comments, (/**/, // etc...), all over my
scripts as well as a very descriptive section at the beginning of the
script.
No correct me if i am wrong but php must still 'read' those comments?

So, do comments technically slow the whole process?
Or is the loss of CPU/Time/memory so negligible that i do not need to worry
about it.

Simon.
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Sims" <si*********@hotmail.com> wrote in message
news:c1*************@ID-162430.news.uni-berlin.de...
Hi,

I proud myself in having good comments, (/**/, // etc...), all over my
scripts as well as a very descriptive section at the beginning of the
script.
No correct me if i am wrong but php must still 'read' those comments?

So, do comments technically slow the whole process?
Or is the loss of CPU/Time/memory so negligible that i do not need to worry about it.

Simon.


For the most part, I would say do not worry about it.

But, if you must, you can do this from the command line

php -w scriptname.php > newname.php

this will strip out all comments, whitespaces.

you can then run your script again, and see if there is a difference.

--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #2

P: n/a
On Sun, 29 Feb 2004 10:20:17 +0200, "Sims" <si*********@hotmail.com> wrote:
I proud myself in having good comments, (/**/, // etc...), all over my
scripts as well as a very descriptive section at the beginning of the
script.
No correct me if i am wrong but php must still 'read' those comments?

So, do comments technically slow the whole process?
Or is the loss of CPU/Time/memory so negligible that i do not need to worry
about it.


I really would not worry about it. It makes the file slightly larger, but
those comments are very valuable, and it's easy for the parser to skip them
anyway.

Just tried an artificial scenario with one file having just an echo, and the
other file having the same echo but 20k of comments. Came out with this:

Benchmark: timing 500 iterations of comments, nocomments...
comments: 43 wallclock secs ( 0.24 usr + 0.84 sys = 1.08 CPU) @ 462.53/s
(n=500)
nocomments: 43 wallclock secs ( 0.29 usr + 0.63 sys = 0.92 CPU) @ 542.89/s
(n=500)

So the difference isn't exactly earth-shattering, and that's with about a
1500:1 comment-to-code ratio. Odds are you'll could make peformance increases
orders of magnitude greater by improving the algorithms in your code rather
than worrying about microseconds potentially saved by not having comments.

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk> / <http://www.andyhsoftware.co.uk/space>
Jul 17 '05 #3

P: n/a

I really would not worry about it. It makes the file slightly larger, but
those comments are very valuable, and it's easy for the parser to skip them anyway.

Just tried an artificial scenario with one file having just an echo, and the other file having the same echo but 20k of comments. Came out with this:

Benchmark: timing 500 iterations of comments, nocomments...
comments: 43 wallclock secs ( 0.24 usr + 0.84 sys = 1.08 CPU) @ 462.53/s (n=500)
nocomments: 43 wallclock secs ( 0.29 usr + 0.63 sys = 0.92 CPU) @ 542.89/s (n=500)

So the difference isn't exactly earth-shattering, and that's with about a
1500:1 comment-to-code ratio. Odds are you'll could make peformance increases orders of magnitude greater by improving the algorithms in your code rather than worrying about microseconds potentially saved by not having comments.


Thanks both for the replies,

I am just trying to 'clean' my code and i am looking at best ways of doing
that.
I am starting to think i need something to run some test for me,

Is there a way to runs stats per page?

Like CPU time. php.exe time, DB time etc and maybe more?
Those would be really helpful to give my boss a really professional looking
site.

Many thanks

Sims
Jul 17 '05 #4

P: n/a
In message <c1*************@ID-162430.news.uni-berlin.de>, Sims
<si*********@hotmail.com> writes

I really would not worry about it. It makes the file slightly larger, but
those comments are very valuable, and it's easy for the parser to skipthem
anyway.

Just tried an artificial scenario with one file having just an echo, and

the
other file having the same echo but 20k of comments. Came out with this:

Benchmark: timing 500 iterations of comments, nocomments...
comments: 43 wallclock secs ( 0.24 usr + 0.84 sys = 1.08 CPU) @

462.53/s
(n=500)
nocomments: 43 wallclock secs ( 0.29 usr + 0.63 sys = 0.92 CPU) @

542.89/s
(n=500)

So the difference isn't exactly earth-shattering, and that's with about a
1500:1 comment-to-code ratio. Odds are you'll could make peformance

increases
orders of magnitude greater by improving the algorithms in your code

rather
than worrying about microseconds potentially saved by not having comments.


Thanks both for the replies,

I am just trying to 'clean' my code and i am looking at best ways of doing
that.


When I come to have to do something to a program someone else has
written, I start by fixing the layout, indentation & comments. I would
not dream of getting rid of comments in the hope it will run a fraction
faster, or produce an 'object' (in the broadest sense) that's a fraction
smaller. IMHO machines are so powerful compared with even a few years
back that what I need to do is concentrate on the functionality and the
elegance of the coding, not the smallness and obscurity of it.

(however I do get rid of 'and now for the clever bit' kind of comments!)

I am starting to think i need something to run some test for me,

Is there a way to runs stats per page?

Like CPU time. php.exe time, DB time etc and maybe more?
Those would be really helpful to give my boss a really professional looking
site.

Many thanks

Sims


--
Five Cats
Email to: cats_spam at uk2 dot net
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.