Am Samstag, 29. Juli 2006 12:29 schrieb Tim Starling:
There were 10000 "foo bar" strings output by each one. On my laptop,
with no bytecode caching, string interpolation was 12 times faster than
concatenation.
I believe this is because you are concatenating a large number of variables
together into one string, which is quite unrealistic for a real-world
application. The more frequent case is where you have only a few variables:
foo = 'foo';
$bar = 'bar';
$start = microtime(TRUE);
for($j = 0; $j < 100; $j++)
for($i = 0; $i < 100000; $i++)
$s = $foo.' '.$bar;
//$s = "$foo $bar";
$stop = microtime(TRUE);
echo $stop-$start;
On my laptop this example needs about 14 secs with interpolation, but only
9-10 secs with concatenation.