cvs: php4 /pear/Benchmark Iterate.php Timer.php
| From: | Sebastian Bergmann | Date: | Thu, 04 Jan 2001 23:55:46 +0000 |
| Subject: | cvs: php4 /pear/Benchmark Iterate.php Timer.php | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-3372@lists.php.net to get a copy of this message | ||
sbergmann Thu Jan 4 15:55:46 2001 EDT
Modified files:
/php4/pear/Benchmark Iterate.php Timer.php
Log:
Added some more documentation. Fixed whitespaces, at least I hope so.
Index: php4/pear/Benchmark/Iterate.php
diff -u php4/pear/Benchmark/Iterate.php:1.2 php4/pear/Benchmark/Iterate.php:1.3
--- php4/pear/Benchmark/Iterate.php:1.2 Thu Jan 4 15:43:32 2001
+++ php4/pear/Benchmark/Iterate.php Thu Jan 4 15:55:46 2001
@@ -16,33 +16,33 @@
// | Authors: Sebastian Bergmann <sb@sebastian-bergmann.de> |
// +----------------------------------------------------------------------+
//
-// $Id: Iterate.php,v 1.2 2001/01/04 23:43:32 sbergmann Exp $
+// $Id: Iterate.php,v 1.3 2001/01/04 23:55:46 sbergmann Exp $
//
- require_once "Benchmark/Timer.php";
+require_once 'Benchmark/Timer.php';
- /**
- * Benchmark::Benchmark_Iterate
- *
- * Purpose:
- *
- * Benchmarking
- *
- * Example:
- *
- * $benchmark = new Benchmark_Iterate;
- *
- * $benchmark->run( "my_function", 100 );
- *
- * $result = $benchmark->get();
- *
- * @author Sebastian Bergmann <sb@phpOpenTracker.de>
- * @version $Revision: 1.2 $
- * @access public
- */
+/**
+* Benchmark::Benchmark_Iterate
+*
+* Purpose:
+*
+* Benchmarking
+*
+* Example:
+*
+* $benchmark = new Benchmark_Iterate;
+*
+* $benchmark->run( 'my_function', 100 );
+*
+* $result = $benchmark->get();
+*
+* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
+* @version $Revision: 1.3 $
+* @access public
+*/
- class Benchmark_Iterate extends Benchmark_Timer
- {
+class Benchmark_Iterate extends Benchmark_Timer
+{
// {{{ run()
/**
@@ -53,16 +53,20 @@
* @access public
*/
- function run( $function, $iterations = 100 )
+ function run($function, $iterations = 100)
{
- for( $i = 1; $i <= $iterations; $i++ )
- {
- $this->set_marker( "start_" . $i );
-
- call_user_func( $function );
-
- $this->set_marker( "end_" . $i );
- }
+ // main loop
+ for($i = 1; $i <= $iterations; $i++)
+ {
+ // set 'start' marker for current iteration
+ $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);
+ }
}
// }}}
@@ -72,8 +76,8 @@
* Returns benchmark result.
*
* $result[ x ] = execution time of iteration x
- * $result[ "mean" ] = mean execution time
- * $result[ "iterations" ] = number of iterations
+ * $result[ 'mean' ] = mean execution time
+ * $result[ 'iterations' ] = number of iterations
*
* @return array $result
* @access public
@@ -81,25 +85,37 @@
function get()
{
- $result = array();
- $total = 0;
+ // init result array
+ $result = array();
+
+ // init variable
+ $total = 0;
+
+ $iterations = count($this->markers)/2;
+
+ // loop through iterations
+ for($i = 1; $i <= $iterations; $i++)
+ {
+ // get elapsed time for current iteration
+ $time = $this->time_elapsed('start_' . $i , 'end_' . $i);
- $iterations = count( $this->markers ) / 2;
+ // sum up total time spent
+ $total = bcadd($total, $time, 6);
- for( $i = 1; $i <= $iterations; $i++ )
- {
- $time = $this->time_elapsed( "start_" . $i , "end_" . $i );
+ // store time
+ $result[ $i ] = $time;
+ }
- $total = bcadd( $total, $time, 6 );
- $result[ $i ] = $time;
- }
+ // calculate and store mean time
+ $result[ 'mean' ] = bcdiv($total, $iterations, 6);
- $result[ "mean" ] = bcdiv( $total, $iterations, 6 );
- $result[ "iterations" ] = $iterations;
+ // store iterations
+ $result[ 'iterations' ] = $iterations;
- return $result;
+ // return result array
+ return $result;
}
// }}}
- }
+}
?>
Index: php4/pear/Benchmark/Timer.php
diff -u php4/pear/Benchmark/Timer.php:1.5 php4/pear/Benchmark/Timer.php:1.6
--- php4/pear/Benchmark/Timer.php:1.5 Thu Jan 4 15:43:32 2001
+++ php4/pear/Benchmark/Timer.php Thu Jan 4 15:55:46 2001
@@ -16,7 +16,7 @@
// | Authors: Sebastian Bergmann <sb@sebastian-bergmann.de> |
// +----------------------------------------------------------------------+
//
-// $Id: Timer.php,v 1.5 2001/01/04 23:43:32 sbergmann Exp $
+// $Id: Timer.php,v 1.6 2001/01/04 23:55:46 sbergmann Exp $
//
/**
@@ -24,20 +24,20 @@
*
* Purpose:
*
- * Timing Script Execution, Generating Profiling Information
+ * Timing Script Execution, Generating Profiling Information
*
* Example:
*
- * $timer = new Benchmark_Timer;
+ * $timer = new Benchmark_Timer;
*
- * $timer->start();
- * $timer->setMarker('Marker 1');
- * $timer->stop();
+ * $timer->start();
+ * $timer->setMarker('Marker 1');
+ * $timer->stop();
*
- * $profiling = $timer->getProfiling();
+ * $profiling = $timer->getProfiling();
*
- * @author Sebastian Bergmann <sb@phpOpenTracker.de>
- * @version $Revision: 1.5 $
+ * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @version $Revision: 1.6 $
* @access public
*/
class Benchmark_Timer