X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2Fbenchmarks%2FBenchmarker.php;h=1559ee959d936597b3c09b4b0e918b6a2a67d7d0;hb=67ede2daaca02a9a34e549ae978e39d01743598a;hp=04aee80210a5f96dc4838fadb75e1d2c720b3d99;hpb=a0b490bbe7a87b54de49f075c59befa8232b2237;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/benchmarks/Benchmarker.php b/maintenance/benchmarks/Benchmarker.php index 04aee80210..1559ee959d 100644 --- a/maintenance/benchmarks/Benchmarker.php +++ b/maintenance/benchmarks/Benchmarker.php @@ -53,6 +53,9 @@ abstract class Benchmarker extends Maintenance { $this->startBench(); $count = $this->getOption( 'count', $this->defaultCount ); $verbose = $this->hasOption( 'verbose' ); + + // Normalise + $normBenchs = []; foreach ( $benchs as $key => $bench ) { // Shortcut for simple functions if ( is_callable( $bench ) ) { @@ -64,6 +67,25 @@ abstract class Benchmarker extends Maintenance { $bench['args'] = []; } + // Name defaults to name of called function + if ( is_string( $key ) ) { + $name = $key; + } else { + if ( is_array( $bench['function'] ) ) { + $name = get_class( $bench['function'][0] ) . '::' . $bench['function'][1]; + } else { + $name = strval( $bench['function'] ); + } + $name = sprintf( "%s(%s)", + $name, + implode( ', ', $bench['args'] ) + ); + } + + $normBenchs[$name] = $bench; + } + + foreach ( $normBenchs as $name => $bench ) { // Optional setup called outside time measure if ( isset( $bench['setup'] ) ) { call_user_func( $bench['setup'] ); @@ -72,6 +94,10 @@ abstract class Benchmarker extends Maintenance { // Run benchmarks $stat = new RunningStat(); for ( $i = 0; $i < $count; $i++ ) { + // Setup outside of time measure for each loop + if ( isset( $bench['setupEach'] ) ) { + $bench['setupEach'](); + } $t = microtime( true ); call_user_func_array( $bench['function'], $bench['args'] ); $t = ( microtime( true ) - $t ) * 1000; @@ -81,21 +107,6 @@ abstract class Benchmarker extends Maintenance { $stat->addObservation( $t ); } - // Name defaults to name of called function - if ( is_string( $key ) ) { - $name = $key; - } else { - if ( is_array( $bench['function'] ) ) { - $name = get_class( $bench['function'][0] ) . '::' . $bench['function'][1]; - } else { - $name = strval( $bench['function'] ); - } - $name = sprintf( "%s(%s)", - $name, - implode( ', ', $bench['args'] ) - ); - } - $this->addResult( [ 'name' => $name, 'count' => $stat->getCount(),