Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.2.9

Bug #4346 [Timer.php] Bug in $result array in getProfiling() method
Submitted: 2005-05-14 19:42 UTC
From: sebastian at thornet dot net Assigned: toggg
Status: Closed Package: Benchmark
PHP Version: 5.0.3 OS: any
Roadmaps: (Not assigned)    
Subscription  


 [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; }

Comments

 [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'] = '-';
 [2005-05-24 13:49 UTC] toggg
This bug has been fixed in CVS. In case this was a documentation problem, the fix will show up at the end of next Sunday (CET) on pear.php.net. In case this was a pear.php.net website problem, the change will show up on the website in short time. Thank you for the report, and for helping us make PEAR better. The initialisation of $temp to the first value in markers was missing. Btw, I corrected a potential display shift if several sessions. Finally, I positived it by adjoining an optionnal output of totals. A bug-fix release will follow in the nexts. Thanks for your feedback.