Posted by sumeet on 10/13/93 11:26
dear friends,
i have a simple code as follows. I would like to know why a single 'echo
$str' is much slower than a echo 'echo $str[$i]'. The results are also
shown below. it shows that ex time for a single 'echo $str' is 0.000142
and for the forloop 'echo $str[$i]' is 0.000047.
include_once('Benchmark/Profiler.php');
include_once('Benchmark/Timer.php');
$str = 'Sumeet Shroff';
$benchmark_timer = new Benchmark_Timer(false);
$benchmark_timer->start();
echo $str;
$benchmark_timer->stop();
echo '<pre>';
echo $benchmark_timer->display();
echo '</pre>';
$benchmark_timer->start();
for( $i = 0; $i < strlen($str); $i++ ) {
echo $str[$i];
}
$benchmark_timer->stop();
echo '<pre>';
echo $benchmark_timer->display();
echo '</pre>';
----------------
time index ex time %
Start 1126422109.93350400 - 0.00%
Stop 1126422109.93364600 0.000142 100.00%
total - 0.000142 100.00%
Sumeet Shroff
time index ex time %
Start 1126422109.93391200 - 0.00%
Stop 1126422109.93395900 0.000047 100.00%
total - 0.000047 100.00%
Sumeet Shroff
www.prateeksha.com
Navigation:
[Reply to this message]
|