enavu webdevmania tutsvalley psdestination
visit the enavu network
6 Comments Article Title Overlay Article Title

How speed improving using single quotes instead of double quotes really is

Articles about speeding up your php are really frequent on the net, and every single one of them includes using single quotes instead od double quotes, at least when you don’t have any variables in that section you are echoing. I did a little test and here is the result.

DZoneDiggDesign FloatDeliciousBlinklistRedditFacebookGoogle BuzzTwitterStumbleUponTumblrShare

According to all those articles php loads faster when echoing something in single quotes then echoing something in double quotes because as we all know when we wrap a variable in single quotes it’s considered as normal text and that means the php engine will just show it without checking for variables in it, on the other side if it’s wrapped in double quotes it’s gonna check if there are variables in it which makes the process longer. That’s true, but how much difference does it make…

I first tried with a small amount of text (few lines). The single quote wrapped text needed from 40ms-70ms and the same result was for double quotes wrapped text. But ok, those are just few lines, no one said it’s much faster when we are echoing small text. So, then i tested it with 3.32MB of pure text. Here is the result…

1

This is the result for single quotes, 17.59 seconds. So naturally we should expect at least one second slowed loading with the next test, double quotes.

2

You probably think i forgot to switch to double quotes, don’t worry i didn’t :) So the result for double quotes is 17.06 seconds.

The conclusion

I made numerous tests with both single and double quotes wrapped text. Sometimes single quotes was a bit faster and sometimes double quotes was a bit faster. The testing was made on a WAMP server on my PC, but i also tested in on the TutsValley’s server and the result are simillar. I needed between 42s and 44s (yea i got a slow internet connection) for both of them, and again sometimes single quotes ware faster and sometimes double quotes ware faster. So how does using single quotes really help us? I don’t know… In my opinion it DOESN’T.

Related posts:

  1. Client side filtering data with jQuery

Slobodan Kustrimovic

This author has yet to fill his BIO.

Did you absolutely LOVE this article... share it!

Comments

  • Interesting. So the more important thing to do is to be consistent with that as you would with any other part of the code.

  • Yup, just find out what’s easier for you and keep with that. :)

  • Good attempt, but this is worthless. This is all done in the PHP lexer, if you want to see the difference you shouldn’t introduce extra variables; you should strip out the pertinent code, and truly benchmark the difference of single-quote vs double quote. Chances are single-quote are faster. Maybe *5* times faster!!! But, 5 times faster on a trivial worthless operation like enabling variable interpolation on a string without variables, is pretty useless in the grand scheme of thing.

    Your conclusion, to be logically sound, should read that it isn’t material to the user experience. Not that the speed difference doesn’t exist at all.

  • Thanks for the comment.

    Which extra variables are you referring to?

    First of all, i tested it with ONLY text, a really BIG text :)

    Second of all, i didn’t say single quotes aren’t faster, that’s logical, the php engine doesn’t check for variables in it.

    What i wanted to point out in this little article is that the overall speed of a page load won’t make much difference, after all, why would a visitor care how much time the php engine needed, he cares how much time the page needs to load.
    :)

  • Hi!
    I haven’t found a date when this post is published. Just want to say that you can’t test server-side script execution speed using client-side stopwatch.
    And check this:
    http://www.php.lt/benchmark/phpbench.php

  • The important time that you will need to check is ‘waiting’ in firebug you will see purple.
    Other times like ‘receiving’, ‘connecting’, etc.
    Can thow other results if you only see the total time.

    Sorry if my english suck

    Bye!

Leave your own!

Sponsors

freedcamp free project management

Popular Articles

fzilla file hosting