News 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

Gonzalo Ayuso's Blog: Checking the performance of PHP exceptions

PHP 10.0 Blog: More on PHP performance

Artur Ejsmont's Blog: Publishing queue messages from PHP using different backends

Larry Garfield's Blog: Benchmarking magic

Hasin Hayder's Blog: Unexpected return value from Facebook FQL.query via PHP REST Lib


Community Events





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


language podcast introduction bugfix package laravel release install api zendserver framework series opinion deployment voicesoftheelephpant library symfony unittest community interview

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