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
// Run benchmarks
$stat = new RunningStat();
for ( $i = 0; $i < $count; $i++ ) {
// 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;
$t = microtime( true );
call_user_func_array( $bench['function'], $bench['args'] );
$t = ( microtime( true ) - $t ) * 1000;
[
'function' => [ $this, 'getPrefixedTextTitle' ],
],
[
'function' => [ $this, 'getPrefixedTextTitle' ],
],
+ 'parseTitleValue cached' => [
'function' => [ $this, 'parseTitleValue' ],
'setup' => [ $this, 'randomize' ],
],
'function' => [ $this, 'parseTitleValue' ],
'setup' => [ $this, 'randomize' ],
],
+ 'parseTitle cached' => [
'function' => [ $this, 'parseTitle' ],
'setup' => [ $this, 'randomize' ],
],
'function' => [ $this, 'parseTitle' ],
'setup' => [ $this, 'randomize' ],
],
+ 'parseTitleValue no cache' => [
+ 'function' => [ $this, 'parseTitleValue' ],
+ 'setupEach' => [ $this, 'randomize' ],
+ ],
+ 'parseTitle no cache' => [
+ 'function' => [ $this, 'parseTitle' ],
+ 'setupEach' => [ $this, 'randomize' ],
+ ],