From 2edce82687c20c838ddd3357f4bc9ad22ba5598c Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Sat, 15 Oct 2011 22:23:50 +0000 Subject: [PATCH] Refactor out duplicate code Add 10 subscribers. Can we have 10 of the same? --- maintenance/benchmarks/benchmarkHooks.php | 32 +++++++++-------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/maintenance/benchmarks/benchmarkHooks.php b/maintenance/benchmarks/benchmarkHooks.php index a9b4722942..59466d07ff 100644 --- a/maintenance/benchmarks/benchmarkHooks.php +++ b/maintenance/benchmarks/benchmarkHooks.php @@ -29,31 +29,25 @@ class BenchmarkHooks extends Benchmarker { } public function execute() { - $time = $this->benchEmptyHooks(); - $this->output( 'Empty hook: ' . $time . "\n" ); - $time = $this->benchLoadedHooks(); - $this->output( 'Loaded hook: ' . $time . "\n" ); - $this->output( "\n" ); - } - - private function benchEmptyHooks( $trials = 1 ) { global $wgHooks; $wgHooks['Test'] = array(); - $start = wfTime(); - for ( $i = 0; $i < $trials; $i++ ) { - wfRunHooks( 'Test' ); - } - $delta = wfTime() - $start; - $pertrial = $delta / $trials; - return sprintf( "Took %6.2fms", - $pertrial ); - } + $time = $this->benchHooks(); + $this->output( 'Empty hook: ' . $time . "\n" ); - private function benchLoadedHooks( $trials = 1 ) { - global $wgHooks; $wgHooks['Test'][] = array( $this, 'test' ); + $time = $this->benchHooks(); + $this->output( 'Loaded (one) hook: ' . $time . "\n" ); + + for( $i = 0; $i < 9; $i++ ) { + $wgHooks['Test'][] = array( $this, 'test' ); + } + $time = $this->benchHooks(); + $this->output( 'Loaded (ten) hook: ' . $time . "\n" ); + $this->output( "\n" ); + } + private function benchHooks( $trials = 1 ) { $start = wfTime(); for ( $i = 0; $i < $trials; $i++ ) { wfRunHooks( 'Test' ); -- 2.20.1