MediaWiki
REL1_24
|
00001 <?php 00024 require_once __DIR__ . '/Benchmarker.php'; 00025 00031 class BenchmarkHooks extends Benchmarker { 00032 public function __construct() { 00033 parent::__construct(); 00034 $this->mDescription = 'Benchmark MediaWiki Hooks.'; 00035 } 00036 00037 public function execute() { 00038 global $wgHooks; 00039 $wgHooks['Test'] = array(); 00040 00041 $time = $this->benchHooks(); 00042 $this->output( 'Empty hook: ' . $time . "\n" ); 00043 00044 $wgHooks['Test'][] = array( $this, 'test' ); 00045 $time = $this->benchHooks(); 00046 $this->output( 'Loaded (one) hook: ' . $time . "\n" ); 00047 00048 for ( $i = 0; $i < 9; $i++ ) { 00049 $wgHooks['Test'][] = array( $this, 'test' ); 00050 } 00051 $time = $this->benchHooks(); 00052 $this->output( 'Loaded (ten) hook: ' . $time . "\n" ); 00053 00054 for ( $i = 0; $i < 90; $i++ ) { 00055 $wgHooks['Test'][] = array( $this, 'test' ); 00056 } 00057 $time = $this->benchHooks(); 00058 $this->output( 'Loaded (one hundred) hook: ' . $time . "\n" ); 00059 $this->output( "\n" ); 00060 } 00061 00066 private function benchHooks( $trials = 10 ) { 00067 $start = microtime( true ); 00068 for ( $i = 0; $i < $trials; $i++ ) { 00069 wfRunHooks( 'Test' ); 00070 } 00071 $delta = microtime( true ) - $start; 00072 $pertrial = $delta / $trials; 00073 00074 return sprintf( "Took %6.3fms", 00075 $pertrial * 1000 ); 00076 } 00077 00081 public function test() { 00082 return true; 00083 } 00084 } 00085 00086 $maintClass = 'BenchmarkHooks'; 00087 require_once RUN_MAINTENANCE_IF_MAIN;