fork download
  1. <?
  2. $str1 = $str2 = "";
  3.  
  4. for ($i=0; $i < 10000; $i++) {
  5. $start = microtime(true);
  6. $str1 .= 'You got ' . $i . ' messages';
  7. $str1_test[] = microtime(true) - $start;
  8. }
  9.  
  10. echo "Dotted: " . ($str1_result = array_sum($str1_test) / 10000);
  11.  
  12. echo PHP_EOL;
  13.  
  14. for ($i=0; $i < 10000; $i++) {
  15. $start = microtime(true);
  16. $str2 .= "You got {$i} messages";
  17. $str2_test[] = microtime(true) - $start;
  18. }
  19.  
  20. echo "Interpolated: " . ($str2_result = array_sum($str2_test) / 10000);
  21. echo PHP_EOL . ($str2_result < $str1_result ? "Interpolation" : "Dot") . " is faster!";
Success #stdin #stdout 0.05s 20568KB
stdin
Standard input is empty
stdout
Dotted: 1.0408401489258E-6
Interpolated: 1.127028465271E-6
Dot is faster!