From: Kunal Mehta Date: Mon, 20 Aug 2018 07:21:49 +0000 (-0700) Subject: benchmarker: Implement setupEach for per-iteration setup X-Git-Tag: 1.34.0-rc.0~4359^2 X-Git-Url: http://git.cyclocoop.org/?a=commitdiff_plain;h=dc9b750b16abe528ee2ae807b56bcff6108fceef;p=lhc%2Fweb%2Fwiklou.git benchmarker: Implement setupEach for per-iteration setup To bypass caches in legacy code where injection doesn't easily work, support a per-iteration setup function, 'setupEach', which runs right before the actual function is timed and called. And use it in benchmarkTitleValue, where I mistakenly assumed that 'setup' did what I wanted. Bug: T201992 Change-Id: I2d01d899bf63576df2833705667f1a16604ab4cc --- diff --git a/maintenance/benchmarks/Benchmarker.php b/maintenance/benchmarks/Benchmarker.php index 9bfebced5d..1559ee959d 100644 --- a/maintenance/benchmarks/Benchmarker.php +++ b/maintenance/benchmarks/Benchmarker.php @@ -94,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; diff --git a/maintenance/benchmarks/benchmarkTitleValue.php b/maintenance/benchmarks/benchmarkTitleValue.php index c60f4bbe82..6bd7953971 100644 --- a/maintenance/benchmarks/benchmarkTitleValue.php +++ b/maintenance/benchmarks/benchmarkTitleValue.php @@ -83,14 +83,22 @@ class BenchmarkTitleValue extends Benchmarker { [ 'function' => [ $this, 'getPrefixedTextTitle' ], ], - [ + 'parseTitleValue cached' => [ 'function' => [ $this, 'parseTitleValue' ], 'setup' => [ $this, 'randomize' ], ], - [ + 'parseTitle cached' => [ 'function' => [ $this, 'parseTitle' ], 'setup' => [ $this, 'randomize' ], ], + 'parseTitleValue no cache' => [ + 'function' => [ $this, 'parseTitleValue' ], + 'setupEach' => [ $this, 'randomize' ], + ], + 'parseTitle no cache' => [ + 'function' => [ $this, 'parseTitle' ], + 'setupEach' => [ $this, 'randomize' ], + ], ] ); }