Single vs double quotes

Submitted by tomek on Sun, 05/08/2011 - 14:01

f1 is slower than f2 by 1.47%

Full source code as executed.
define('LOOP',1000000);
function f1() {
  ob_start();
  for($i=0; $i<LOOP; ++$i) {
    echo '123456';
    echo '123456';
    echo '123456';
    echo '123456';
    echo '123456';
  }
  ob_end_clean();
}
 
function f2() {
  ob_start();
  for($i=0; $i<LOOP; ++$i) {
    echo "123456";
    echo "123456";
    echo "123456";
    echo "123456";
    echo "123456";
  }
  ob_end_clean();
}
 
$start = microtime(true);
f1();
$stop = microtime(true);
$time1 = $stop - $start;
 
$start = microtime(true);
f2();
$stop = microtime(true);
$time2 = $stop - $start;
 
echo $time1 . "\t";
echo $time2 . "\n";
Test results
comparisontime1time2php_version
3.61%8977818665005.3.5-1ubuntu7.2
6.8%9083319700835.3.3-7
0.22%172107017172155.3.5-1ubuntu7.2
3.67%107126711105625.3.3-7+squeeze1
2.44%143378139960php-5.3.6-phpbrew_compiled
2.81%147421143393php-5.3.7-phpbrew_compiled
2.02%153466150430php-5.3.8-phpbrew_compiled
2.15%147312144215php-5.3.9-phpbrew_compiled
1.82%147872145224php-5.3.10-phpbrew_compiled
2.41%144886141470php-5.3.11-phpbrew_compiled
2.05%147173144222php-5.3.12-phpbrew_compiled
2.25%144675141489php-5.3.13-phpbrew_compiled
2.61%164406160231php-5.3.14-phpbrew_compiled
2.28%147591144302php-5.3.15-phpbrew_compiled
2.66%146500142699php-5.3.16-phpbrew_compiled
2.87%147192143085php-5.3.17-phpbrew_compiled
2.3%166279162545php-5.3.18-phpbrew_compiled
2.54%162686158649php-5.3.19-phpbrew_compiled
1.42%185909183303php-5.4.0-phpbrew_compiled
1.77%185027181812php-5.4.1-phpbrew_compiled
1.53%184179181405php-5.4.2-phpbrew_compiled
2.15%188355184384php-5.4.3-phpbrew_compiled
1.49%190603187810php-5.4.4-phpbrew_compiled
1.14%183785181708php-5.4.5-phpbrew_compiled
1.24%186192183914php-5.4.6-phpbrew_compiled
1.27%187304184958php-5.4.7-phpbrew_compiled
1.28%182629180321php-5.4.8-phpbrew_compiled
1.42%203694200834php-5.4.9-phpbrew_compiled
50%
updown
50%