News Feed
Jobs Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Nikita Popov's Blog:
Disproving the Single Quotes Performance Myth
January 10, 2012 @ 09:47:55

In this new post to his blog Nikita Popov aims to dispel the popular micro-optimization myth of using single quotes over double quotes for a performance boost.

If there is one PHP related thing that I really hate, then it is definitely the Single Quotes Performance Myth. [...] Let's do a random Google search for "PHP single quotes performance": You will get many results telling you that single quotes are faster than double quotes and that string interpolation is much slower than string concatenation. Most of them advise to use single quotes and concatenation to improve the performance of your application. Let's be clear here: This is pointless.

He did some benchmarking of his own to see how the myth would hold up and, as it turns out, it doesn't - "There is none". His proof compares two strings, one normal single-quoted and the other a double-quoted, and the opcodes they generate. They end up exactly the same. Since it's the opcodes that matter, he recommends using something like APC if you're really worried about the performance. He also includes an example using the token_get_all function of PHP to see how fast the strings run through the lexer too (again, almost no difference).

As an added bonus, he also throws in a bit about string concatenation versus string interpolation with some benchmarking scripts and results of their own.

0 comments voice your opinion now!
singlequote doublequote myth microoptimization benchmark string


blog comments powered by Disqus

Similar Posts

Mark Kimsal's Blog: Addslashes(): don't call it a comeback

PHPBuilder.com: An introduction to PEAR's Validate package

Davey Shafik's Blog: AJAX and PHP End-to-End Debugging

PHP in Action: Type hints are more useful for scalars than objects

Larry Garfield's Blog: readfile() not considered harmful


Community Events











Don't see your event here?
Let us know!


podcast example framework unittest install component symfony2 hhvm release opinion application composer facebook hack security overview introduction package language code

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework