MediaWiki
REL1_19
|
00001 <?php 00022 require_once( dirname( __FILE__ ) . '/Benchmarker.php' ); 00023 00024 class BenchmarkHooks extends Benchmarker { 00025 00026 public function __construct() { 00027 parent::__construct(); 00028 $this->mDescription = 'Benchmark MediaWiki Hooks.'; 00029 } 00030 00031 public function execute() { 00032 global $wgHooks; 00033 $wgHooks['Test'] = array(); 00034 00035 $time = $this->benchHooks(); 00036 $this->output( 'Empty hook: ' . $time . "\n" ); 00037 00038 $wgHooks['Test'][] = array( $this, 'test' ); 00039 $time = $this->benchHooks(); 00040 $this->output( 'Loaded (one) hook: ' . $time . "\n" ); 00041 00042 for( $i = 0; $i < 9; $i++ ) { 00043 $wgHooks['Test'][] = array( $this, 'test' ); 00044 } 00045 $time = $this->benchHooks(); 00046 $this->output( 'Loaded (ten) hook: ' . $time . "\n" ); 00047 00048 for( $i = 0; $i < 90; $i++ ) { 00049 $wgHooks['Test'][] = array( $this, 'test' ); 00050 } 00051 $time = $this->benchHooks(); 00052 $this->output( 'Loaded (one hundred) hook: ' . $time . "\n" ); 00053 $this->output( "\n" ); 00054 } 00055 00060 private function benchHooks( $trials = 10 ) { 00061 $start = wfTime(); 00062 for ( $i = 0; $i < $trials; $i++ ) { 00063 wfRunHooks( 'Test' ); 00064 } 00065 $delta = wfTime() - $start; 00066 $pertrial = $delta / $trials; 00067 return sprintf( "Took %6.2fs", 00068 $pertrial ); 00069 } 00070 00074 public function test() { 00075 return true; 00076 } 00077 } 00078 00079 $maintClass = 'BenchmarkHooks'; 00080 require_once( RUN_MAINTENANCE_IF_MAIN );