Single vs double quotes

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

f2 is slower than f1 by 1.66%

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
50%
updown
50%