From: Sam Reed Date: Sat, 15 Oct 2011 22:15:36 +0000 (+0000) Subject: Rudimentary hook benchmarks X-Git-Tag: 1.31.0-rc.0~27085 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin//%22%24path/%7B%24disabledImages%5B%24type%5D%7D/%22?a=commitdiff_plain;h=1598d4d8b610b87322d73865da14d9c4fe1b2f5f;p=lhc%2Fweb%2Fwiklou.git Rudimentary hook benchmarks --- 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 );