MediaWiki  REL1_20
benchmarkHooks.php
Go to the documentation of this file.
00001 <?php
00024 require_once( __DIR__ . '/Benchmarker.php' );
00025 
00031 class BenchmarkHooks extends Benchmarker {
00032 
00033         public function __construct() {
00034                 parent::__construct();
00035                 $this->mDescription = 'Benchmark MediaWiki Hooks.';
00036         }
00037 
00038         public function execute() {
00039                 global $wgHooks;
00040                 $wgHooks['Test'] = array();
00041 
00042                 $time = $this->benchHooks();
00043                 $this->output( 'Empty hook: ' . $time . "\n" );
00044 
00045                 $wgHooks['Test'][] = array( $this, 'test' );
00046                 $time = $this->benchHooks();
00047                 $this->output( 'Loaded (one) hook: ' . $time . "\n" );
00048 
00049                 for( $i = 0; $i < 9; $i++ ) {
00050                         $wgHooks['Test'][] = array( $this, 'test' );
00051                 }
00052                 $time = $this->benchHooks();
00053                 $this->output( 'Loaded (ten) hook: ' . $time . "\n" );
00054 
00055                 for( $i = 0; $i < 90; $i++ ) {
00056                         $wgHooks['Test'][] = array( $this, 'test' );
00057                 }
00058                 $time = $this->benchHooks();
00059                 $this->output( 'Loaded (one hundred) hook: ' . $time . "\n" );
00060                 $this->output( "\n" );
00061         }
00062 
00067         private function benchHooks( $trials = 10 ) {
00068                 $start = microtime( true );
00069                 for ( $i = 0; $i < $trials; $i++ ) {
00070                         wfRunHooks( 'Test' );
00071                 }
00072                 $delta = microtime( true ) - $start;
00073                 $pertrial = $delta / $trials;
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 );