3 * Create a doxygen subgroup of Maintenance for benchmarks
4 * @defgroup Benchmark Benchmark
9 * TODO: report PHP version, OS ..
14 require_once( dirname( __FILE__
) . '/../Maintenance.php' );
15 abstract class Benchmarker
extends Maintenance
{
18 public function __construct() {
19 parent
::__construct();
20 $this->addOption( 'count', "How many time to run a benchmark", false, true );
23 public function bench( array $benchs ) {
25 $count = $this->getOption( 'count', 100 );
27 foreach( $benchs as $bench ) {
29 if(!array_key_exists( 'args', $bench )) {
30 $bench['args'] = array();
35 for( $i=0; $i<$count; $i++
) {
36 call_user_func_array( $bench['function'], $bench['args'] );
38 $delta = wfTime() - $start;
40 // function passed as a callback
41 if( is_array( $bench['function'] ) ) {
42 $ret = get_class( $bench['function'][0] ). '->' . $bench['function'][1];
43 $bench['function'] = $ret;
46 $this->results
[$bench_number] = array(
47 'function' => $bench['function'],
48 'arguments' => $bench['args'],
51 'average' => $delta / $count,
56 public function getFormattedResults( ) {
58 foreach( $this->results
as $res ) {
59 // show function with args
60 $ret .= sprintf( "%s times: function %s(%s) :\n",
63 join( ', ', $res['arguments'] )
65 $ret .= sprintf( " %6.2fms (%6.2fms each)\n",
67 $res['average'] * 1000