Skip to content

Instantly share code, notes, and snippets.

@fwolf
Created October 27, 2013 14:06
Show Gist options
  • Save fwolf/7182566 to your computer and use it in GitHub Desktop.
Save fwolf/7182566 to your computer and use it in GitHub Desktop.
Speed benchmark for PHP single-quote VS double-quote. Result: almose same.
<?php
$blah="blah"; $s=microtime(true); for($i=0;$i<100000;$i++) 'omgwtf'.$blah."\n"; echo microtime(true)-$s . "\n"; $s=microtime(true); for($i=0;$i<100000;$i++) "omgwtf{$blah}\n"; echo microtime(true)-$s . "\n";
@fwolf
Copy link
Author

fwolf commented Oct 27, 2013

https://groups.google.com/forum/#!topic/make-the-web-faster/3fvoLdgECMw

Nothing is wrong with the statement, you're just not interpreting it
very accurately...the difference is very small and slightly in the
favor of single quotes whenever a handful of variables are used.
However, when no variables are used, double quotes may be faster
because of implementation details in the engine.

These micro-optimizations can't get you more than 1 or 2 extra
requests per second done on a box...if that request has several tens
of thousands of variable interpolation operations. This is a LOT of
work for no real reward. Caching solutions and configuration tweaks
yield much higher results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment