So I assume that comments count towards the file total size. So also I assume comments affect the download speed of the file, however negligible that may be. But the browser does not read the comments. So they do not affect the processing time. Is that all correct? Sort of like if a tree falls in a forest and nowbody is there to hear it does it make a sound?

I am using this php file and it has a tremendous amount of comments - more than the code it self. So I figured I would just keep the original and strip them all out of the file I'm using. But if somehow comments don't affect speed at all I can leave them in the original.

Jeff_Mott
—
2013-02-19T23:24:51Z —
#2

To be technically correct, I'd have to say that comments add to the processing time, if only for the compiler to parse several extra tokens. However, as a practical matter, that extra processing time is very likely to be astronomically small. If in doubt, benchmarking will definitively answer this question. You can create both versions of the file -- one with comments and one without -- and measure which one runs faster, and by how much.

PicnicTutorials
—
2013-02-19T23:29:41Z —
#3

Which tool online or otherwise do I use to benchmark it?

Jeff_Mott
—
2013-02-19T23:37:09Z —
#4

For JS, Benchmark.js (which is the library behind jsperf.com). For PHP, I think people usually just measure with microtime(true).

PicnicTutorials
—
2013-02-19T23:38:59Z —
#5

How do I use microtime(true)?

Jeff_Mott
—
2013-02-19T23:44:13Z —
#6

EricWatson said:

How do I use microtime(true)?

$start = microtime(true);
/*
In here, put the code you want to test.
To ensure you capture the parsing time,
you may want to bring the test code in with include/require/eval.
*/
$stop = microtime(true);

dresden_phoenix
—
2013-02-20T02:02:34Z —
#7

All data counts, even white spaces. a file with 10 \'s is bigger than a file with none. As far as d/l time a commented character weighs just as much as one character of code, so no comment size is NOT 'negligible'.

I don't remember if comments are parsed out or simply skipped either way as they are not instructions they don't present a processing load.

That being said, and I am saying this tho I am particularly lazy and stingy with my comments, commenting your code is GOOD PRACTICE. Have you ever written a brilliant piece of elegant code and gone back to it 2 years later ? What if you have to work with a team? trust me comments are quite worth their weight.

Think about it. You could 'streamline' code and probably even type quicker by not thinking of meaningful variable names. Instead of: namesOfPeeps=new array('ray', 'veronica', 'havoc', 'bushy', 'eric', 'paul') you could simply code: a=new array('ray', 'veronica', 'havoc', 'bushy', 'eric', 'paul') and save 11 characters, plus the typing time, plus the time of coming up with a meaningful name for your variable. But trust me, in any piece of code with more than four variables this will not be worth the hours of debugging time, the difficulty it will present when revisiting and revising this code for later use , and the fact that the code will be difficult to share with colleagues.

Really if you have streamed line your code so that the only things that bares reviewing is your commenting habits , you have earned a break and probably don't need to streamline any further at all. Other wise it best to focus on real bottle necks like redundancy, inefficient functions, server requests, heck even image sizes.

BTWsome people keep a production version ( commented, formatted and easy to read) of their code and a work version (uncommented, minimized, all superfluous white space characters deleted , and completely unreadable by humans). That's an option, if you dont mind the extra logistics.