cvs: php4 /pear/Benchmark Iterate.php
| From: | Martin Jansen | Date: | Fri, 02 Mar 2001 18:24:00 +0000 |
| Subject: | cvs: php4 /pear/Benchmark Iterate.php | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-4351@lists.php.net to get a copy of this message | ||
mj Fri Mar 2 10:24:00 2001 EDT
Modified files:
/php4/pear/Benchmark Iterate.php
Log:
- added check for existing bcmath extensions
to Benchmark/Iterate.php
- did some cosmetic changes to Benchmark/Iterate.php
Index: php4/pear/Benchmark/Iterate.php
diff -u php4/pear/Benchmark/Iterate.php:1.4 php4/pear/Benchmark/Iterate.php:1.5
--- php4/pear/Benchmark/Iterate.php:1.4 Tue Jan 9 17:01:53 2001
+++ php4/pear/Benchmark/Iterate.php Fri Mar 2 10:23:59 2001
@@ -16,7 +16,7 @@
// | Authors: Sebastian Bergmann <sb@sebastian-bergmann.de> |
// +----------------------------------------------------------------------+
//
-// $Id: Iterate.php,v 1.4 2001/01/10 01:01:53 ssb Exp $
+// $Id: Iterate.php,v 1.5 2001/03/02 18:23:59 mj Exp $
//
require_once 'Benchmark/Timer.php';
@@ -32,12 +32,12 @@
*
* $benchmark = new Benchmark_Iterate;
*
-* $benchmark->run( 'my_function', 100 );
+* $benchmark->run('my_function', 100);
*
* $result = $benchmark->get();
*
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
-* @version $Revision: 1.4 $
+* @version $Revision: 1.5 $
* @access public
*/
@@ -59,13 +59,13 @@
for($i = 1; $i <= $iterations; $i++)
{
// set 'start' marker for current iteration
- $this->set_marker('start_' . $i);
+ $this->set_marker('start_'.$i);
// call function to be benchmarked
call_user_func($function);
// set 'end' marker for current iteration
- $this->set_marker('end_' . $i);
+ $this->set_marker('end_'.$i);
}
}
@@ -75,9 +75,9 @@
/**
* Returns benchmark result.
*
- * $result[ x ] = execution time of iteration x
- * $result[ 'mean' ] = mean execution time
- * $result[ 'iterations' ] = number of iterations
+ * $result[x ] = execution time of iteration x
+ * $result['mean' ] = mean execution time
+ * $result['iterations'] = number of iterations
*
* @return array $result
* @access public
@@ -97,20 +97,28 @@
for($i = 1; $i <= $iterations; $i++)
{
// get elapsed time for current iteration
- $time = $this->time_elapsed('start_' . $i , 'end_' . $i);
+ $time = $this->time_elapsed('start_'.$i , 'end_'.$i);
// sum up total time spent
- $total = bcadd($total, $time, 6);
-
+ if (extension_loaded('bcmath')) {
+ $total = bcadd($total, $time, 6);
+ } else {
+ $total = $total + $time;
+ }
+
// store time
- $result[ $i ] = $time;
+ $result[$i] = $time;
}
// calculate and store mean time
- $result[ 'mean' ] = bcdiv($total, $iterations, 6);
+ if (extension_loaded('bcmath')) {
+ $result['mean'] = bcdiv($total, $iterations, 6);
+ } else {
+ $result['mean'] = $total / $iterations;
+ }
// store iterations
- $result[ 'iterations' ] = $iterations;
+ $result['iterations'] = $iterations;
// return result array
return $result;