<?php
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
define('ITERATIONS', 10000);
header('Content-Type: text/plain');
printf("Starting benchmark, over %d iterations:\r\n\r\n", ITERATIONS);
print("Imploding...");
$start = microtime_float();
$list = Array();
for ($_ = 0; $_ < ITERATIONS; $_++)
$list[] = 'a';
$result = implode('',$list);
$end = microtime_float() - $start;
printf("%0.3f seconds\r\n", $end);
unset($list,$result);
print("Concatenating...");
$start = microtime_float();
$result = '';
for ($_ = 0; $_ < ITERATIONS; $_++)
$result .= 'a';
$end = microtime_float() - $start;
printf("%0.3f seconds\r\n", $end);
?>
приводит к увеличению времени взрыва в 99% случаев.например,
Starting benchmark, over 10000 iterations:
Imploding...0.007 seconds
Concatenating...0.003 seconds