PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Benchmarking » Benchmark » Bug #4346

[Timer.php] Bug in $result array in getProfiling() method

Details

Submitted2005-05-14 19:42 UTC
Fromsebastian at thornet dot net
Assignedtoggg
StatusClosed
PackageBenchmark
PHP Version5.0.3
OSany
Roadmaps(Not assigned)

Comments

[2005-05-14 19:42 UTC] sebastian at thornet dot net

Description:
------------
I think there is a bug in the getProfiling() method in Benchmark_Timer class. The $profiling[x]['total'] is equal to time index of marker x. Also look at in description of this method:
'$profiling[x]['total'] = total execution time up to marker x'
but in the array we've got a time index not execution time!

Reproduce code:
---------------
if (extension_loaded('bcmath')) {
$diff = bcsub($time, $temp, 6);
$total = bcadd($total, $diff, 6);
} else {
$diff = $time - $temp;
$total = $total + $diff;
}

Expected result:
----------------
In every marker $result[$i]['total'] == $result[$i]['time']

Actual result:
--------------
This should resolve the problem:

if ($i == 0) $f_time = $time;

if (extension_loaded('bcmath')) {
$diff = bcsub($time, $temp, 6);
$total = bcsub($time, $f_time, 6);
} else {
$diff = $time - $temp;
$total = $time - $f_time;
}

[2005-05-17 13:49 UTC] tpavlakos at yahoo dot gr

[referring to the foreach loop, inside getProfiling function]
I think the correct solution would be to keep $diff in the correct state all the time (i.e. not letting it have a wrong value for $i=0 inside the loop and then fixing this value later on).
Apart from code clarity, this seems to be the reason for the introduction of the bug (if you ask me anyway...)

==CODE==
$diff = 0
...
foreach ($this->markers as $marker => $time) {
if (extension_loaded('bcmath')) {
$diff = ( $i == 0 ? 0 : bcsub($time, $temp, 6) );
$total = bcadd($total, $diff, 6);
} else {
$diff = ( $i == 0 ? 0 : $time - $temp );
$total = $total + $diff;
}

and then delete the folowing line:
$result[0]['diff'] = '-';