sbergmann Fri Mar 2 22:36:45 2001 EDT
Modified files:
/php4/pear/Benchmark Iterate.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]