cvs: php4 /pear/Benchmark Benchmark.php
| From: | Sebastian Bergmann | Date: | Thu, 28 Sep 2000 16:15:59 +0000 |
| Subject: | cvs: php4 /pear/Benchmark Benchmark.php | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-1858@lists.php.net to get a copy of this message | ||
sbergmann Thu Sep 28 09:15:59 2000 EDT
Added files:
/php4/pear/Benchmark Benchmark.php
Log:
First draft of Benchmark::Benchmark.
Index: php4/pear/Benchmark/Benchmark.php
+++ php4/pear/Benchmark/Benchmark.php
<?php
//
// +----------------------------------------------------------------------+
// | PHP version 4.0 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt.
|
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Sebastian Bergmann <sb@phpOpenTracker.de> |
// +----------------------------------------------------------------------+
//
// $Id: Benchmark.php,v 1.1 2000/09/28 16:15:59 sbergmann Exp $
//
require_once "Benchmark/Timer.php";
/**
* Benchmark::Benchmark
*
* Purpose:
*
* Benchmarking
*
* Example:
*
* $benchmark = new Benchmark;
*
* $benchmark->benchmark( "my_function", 100 );
*
* $result = $benchmark->get_benchmark();
*
* @author Sebastian Bergmann <sb@phpOpenTracker.de>
* @version 1.0 28/09/00
* @access public
*/
class Benchmark
{
// {{{ properties
/**
* Benchmark::Timer instance.
*
* @var object
* @access private
*/
var $timer;
// }}}
// {{{ Benchmark()
/**
* Constructor.
*
* @access public
*/
function Benchmark()
{
$this->timer = new Benchmark_Timer;
}
// }}}
// {{{ run()
/**
* 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 )
{
for( $i = 1; $i <= $iterations; $i++ )
{
$this->timer->set_marker( "start_" . $i );
call_user_func( $function );
$this->timer->set_marker( "end_" . $i );
}
}
// }}}
// {{{ get()
/**
* Returns benchmark result.
*
* $result[ x ] = execution time of iteration x
* $result[ "mean" ] = mean execution time
* $result[ "iterations" ] = number of iterations
*
* @return array $result
* @access public
*/
function get()
{
$result = array();
$total = 0;
$iterations = count( $this->timer->markers ) / 2;
for( $i = 1; $i <= $iterations; $i++ )
{
$time = $this->timer->time_elapsed( "start_" . $i , "end_" . $i );
$total = bcadd( $total, $time, 6 );
$result[ $i ] = $time;
}
$result[ "mean" ] = bcdiv( $total, $iterations, 6 );
$result[ "iterations" ] = $iterations;
return $result;
}
// }}}
}
?>