SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)

    How do /* comments */ work when it comes to browser downloading the file?

    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.

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,263
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    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.
    "First make it work. Then make it better."

  3. #3
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Which tool online or otherwise do I use to benchmark it?

  4. #4
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,263
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    For JS, Benchmark.js (which is the library behind jsperf.com). For PHP, I think people usually just measure with microtime(true).
    "First make it work. Then make it better."

  5. #5
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    How do I use microtime(true)?

  6. #6
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,263
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by EricWatson View Post
    How do I use microtime(true)?
    PHP Code:
    $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); 
    "First make it work. Then make it better."

  7. #7
    Community Advisor silver trophybronze trophy
    dresden_phoenix's Avatar
    Join Date
    Jun 2008
    Location
    Madison, WI
    Posts
    2,798
    Mentioned
    34 Post(s)
    Tagged
    2 Thread(s)
    All data counts, even white spaces. a file with 10 \n'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.

    BTW
    some 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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •