Quick hacky benchmark: http://meta.wikimedia.org/wiki/PHP_string_looping
Executive summary: using the append operator ($result .= "*") is relatively speedy. Copying strings ($result = $result . "*") is really reaaaaally slow.
'Relatively speedy' is tempered by the general sluggishness of PHP; per-iteration loop overhead is itself larger than an append operation.
-- brion vibber (brion @ pobox.com)
Brion Vibber wrote:
Quick hacky benchmark: http://meta.wikimedia.org/wiki/PHP_string_looping
Executive summary: using the append operator ($result .= "*") is relatively speedy. Copying strings ($result = $result . "*") is really reaaaaally slow.
'Relatively speedy' is tempered by the general sluggishness of PHP; per-iteration loop overhead is itself larger than an append operation.
-- brion vibber (brion @ pobox.com)
Hello brion
Can you benchmark the following code against the two aboves ?
while (something) { $result[$i] = '*'; $i++; } $newresult = implode('', $result);
Maybe even : $result = (string) implode('', $result);
Ashar Voultoiz wrote:
Can you benchmark the following code against the two aboves ?
while (something) { $result[$i] = '*'; $i++; } $newresult = implode('', $result);
Where 'something' is '$i < TEST_SIZE' this performs about the same as the for loop version.
-- brion vibber (brion @ pobox.com)
wikitech-l@lists.wikimedia.org