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

John Walsh's Blog: PHP Benchmark - For vs While

Symfony Blog: Is symfony too slow for real-world usage?

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

2bits.com: Benchmarking Zend Server Community Edition with Drupal

Gonzalo Ayuso's Blog: Database Abstraction Layers in PHP. PDO versus DBAL


Community Events

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


php7 library application conference community laravel series performance symfony2 configure interview language framework podcast opinion introduction release install api example

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