From 1598d4d8b610b87322d73865da14d9c4fe1b2f5f Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Sat, 15 Oct 2011 22:15:36 +0000 Subject: [PATCH] Rudimentary hook benchmarks --- maintenance/benchmarks/benchmarkHooks.php | 73 +++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 maintenance/benchmarks/benchmarkHooks.php diff --git a/maintenance/benchmarks/benchmarkHooks.php b/maintenance/benchmarks/benchmarkHooks.php new file mode 100644 index 0000000000..a9b4722942 --- /dev/null +++ b/maintenance/benchmarks/benchmarkHooks.php @@ -0,0 +1,73 @@ +mDescription = "Benchmark MediaWiki Hooks."; + } + + 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 ); + } + + private function benchLoadedHooks( $trials = 1 ) { + global $wgHooks; + $wgHooks['Test'][] = array( $this, 'test' ); + + $start = wfTime(); + for ( $i = 0; $i < $trials; $i++ ) { + wfRunHooks( 'Test' ); + } + $delta = wfTime() - $start; + $pertrial = $delta / $trials; + return sprintf( "Took %6.2fms", + $pertrial ); + } + + public function test() { + return true; + } +} + +$maintClass = "BenchmarkHooks"; +require_once( RUN_MAINTENANCE_IF_MAIN ); -- 2.20.1