[PHP-CVS] cvs: php4 /pear/Benchmark Iterate.php

2001-03-02 Thread Sebastian Bergmann

sbergmann   Fri Mar  2 22:36:45 2001 EDT

  Modified files:  
/php4/pear/BenchmarkIterate.php 
  Log:
  Use call_user_func_array() in order to profile functions that take arguments.
  
Index: php4/pear/Benchmark/Iterate.php
diff -u php4/pear/Benchmark/Iterate.php:1.5 php4/pear/Benchmark/Iterate.php:1.6
--- php4/pear/Benchmark/Iterate.php:1.5 Fri Mar  2 10:23:59 2001
+++ php4/pear/Benchmark/Iterate.php Fri Mar  2 22:36:44 2001
@@ -16,7 +16,7 @@
 // | Authors: Sebastian Bergmann [EMAIL PROTECTED]   |
 // +--+
 //
-// $Id: Iterate.php,v 1.5 2001/03/02 18:23:59 mj Exp $
+// $Id: Iterate.php,v 1.6 2001/03/03 06:36:44 sbergmann Exp $
 //
 
 require_once 'Benchmark/Timer.php';
@@ -30,14 +30,19 @@
 * 
 * Example:
 * 
+* require_once "Benchmark/Iterate.php";
 * $benchmark = new Benchmark_Iterate;
 * 
-* $benchmark-run('my_function', 100);
+* function foo($string)
+* {
+* print $string."br";
+* }
 * 
+* $benchmark-run(100, 'foo', 'test');
 * $result = $benchmark-get();
 * 
 * @author   Sebastian Bergmann [EMAIL PROTECTED]
-* @version  $Revision: 1.5 $
+* @version  $Revision: 1.6 $
 * @access   public
 */
 
@@ -48,24 +53,27 @@
 /**
 * Benchmarks a function.
 *
-* @param  string  $function   name of the function to be benchmarked
-* @param  int $iterations number of iterations (default: 100)
 * @access public
 */
 
-function run($function, $iterations = 100)
+function run()
 {
+// get arguments
+$arguments = func_get_args();
+$iterations = array_shift($arguments);
+$function_name = array_shift($arguments);
+
 // main loop
-for($i = 1; $i = $iterations; $i++)
+for ($i = 1; $i = $iterations; $i++)
 {
 // set 'start' marker for current iteration
-$this-set_marker('start_'.$i);
+$this-setMarker('start_'.$i);
 
 // call function to be benchmarked
-call_user_func($function);
+call_user_func_array($function_name, $arguments);
 
 // set 'end' marker for current iteration
-$this-set_marker('end_'.$i);
+$this-setMarker('end_'.$i);
 }
 }
 
@@ -94,10 +102,10 @@
 $iterations = count($this-markers)/2;
 
 // loop through iterations
-for($i = 1; $i = $iterations; $i++)
+for ($i = 1; $i = $iterations; $i++)
 {
 // get elapsed time for current iteration
-$time = $this-time_elapsed('start_'.$i , 'end_'.$i);
+$time = $this-timeElapsed('start_'.$i , 'end_'.$i);
 
 // sum up total time spent
 if (extension_loaded('bcmath')) {



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-CVS] cvs: php4 /pear/Benchmark Iterate.php

2001-03-02 Thread Martin Jansen

mj  Fri Mar  2 10:24:00 2001 EDT

  Modified files:  
/php4/pear/BenchmarkIterate.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 [EMAIL PROTECTED]   |
 // +--+
 //
-// $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 [EMAIL PROTECTED]
-* @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;



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]