From: Timo Tijhof Date: Thu, 16 Aug 2018 17:11:14 +0000 (+0100) Subject: benchmarks: Create $normBenchs before the run instead of during X-Git-Tag: 1.34.0-rc.0~4407^2 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=63ef2a8a39732bd97f17c29ac44fe0b88e2e63b6;p=lhc%2Fweb%2Fwiklou.git benchmarks: Create $normBenchs before the run instead of during Separates the concerns a bit better, and also makes the code easier to debug with less distracting steps during the running of the benchmark. Change-Id: Ia5a18216cb77d39fd60cd76b23ebceee7324a250 --- diff --git a/maintenance/benchmarks/Benchmarker.php b/maintenance/benchmarks/Benchmarker.php index 04aee80210..9bfebced5d 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'] ); @@ -81,21 +103,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(),