mDescription = 'Benchmark MediaWiki Hooks.'; } public function execute() { global $wgHooks; $wgHooks['Test'] = array(); $time = $this->benchHooks(); $this->output( 'Empty hook: ' . $time . "\n" ); $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" ); for( $i = 0; $i < 90; $i++ ) { $wgHooks['Test'][] = array( $this, 'test' ); } $time = $this->benchHooks(); $this->output( 'Loaded (one hundred) hook: ' . $time . "\n" ); $this->output( "\n" ); } /** * @param $trials int * @return string */ private function benchHooks( $trials = 10 ) { $start = microtime( true ); for ( $i = 0; $i < $trials; $i++ ) { wfRunHooks( 'Test' ); } $delta = microtime( true ) - $start; $pertrial = $delta / $trials; return sprintf( "Took %6.3fms", $pertrial * 1000 ); } /** * @return bool */ public function test() { return true; } } $maintClass = 'BenchmarkHooks'; require_once( RUN_MAINTENANCE_IF_MAIN );