Index: trunk/phase3/maintenance/benchmarks/benchmarkHooks.php |
— | — | @@ -0,0 +1,73 @@ |
| 2 | +<?php
|
| 3 | +/**
|
| 4 | + * This program is free software; you can redistribute it and/or modify
|
| 5 | + * it under the terms of the GNU General Public License as published by
|
| 6 | + * the Free Software Foundation; either version 2 of the License, or
|
| 7 | + * (at your option) any later version.
|
| 8 | + *
|
| 9 | + * This program is distributed in the hope that it will be useful,
|
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 | + * GNU General Public License for more details.
|
| 13 | + *
|
| 14 | + * You should have received a copy of the GNU General Public License along
|
| 15 | + * with this program; if not, write to the Free Software Foundation, Inc.,
|
| 16 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
| 17 | + * http://www.gnu.org/copyleft/gpl.html
|
| 18 | + *
|
| 19 | + * @file
|
| 20 | + * @ingroup Maintenance
|
| 21 | + */
|
| 22 | +
|
| 23 | +require_once( dirname( __FILE__ ) . '/Benchmarker.php' );
|
| 24 | +
|
| 25 | +class BenchmarkHooks extends Benchmarker {
|
| 26 | +
|
| 27 | + public function __construct() {
|
| 28 | + parent::__construct();
|
| 29 | + $this->mDescription = "Benchmark MediaWiki Hooks.";
|
| 30 | + }
|
| 31 | +
|
| 32 | + public function execute() {
|
| 33 | + $time = $this->benchEmptyHooks();
|
| 34 | + $this->output( 'Empty hook: ' . $time . "\n" );
|
| 35 | + $time = $this->benchLoadedHooks();
|
| 36 | + $this->output( 'Loaded hook: ' . $time . "\n" );
|
| 37 | + $this->output( "\n" );
|
| 38 | + }
|
| 39 | +
|
| 40 | + private function benchEmptyHooks( $trials = 1 ) {
|
| 41 | + global $wgHooks;
|
| 42 | + $wgHooks['Test'] = array();
|
| 43 | +
|
| 44 | + $start = wfTime();
|
| 45 | + for ( $i = 0; $i < $trials; $i++ ) {
|
| 46 | + wfRunHooks( 'Test' );
|
| 47 | + }
|
| 48 | + $delta = wfTime() - $start;
|
| 49 | + $pertrial = $delta / $trials;
|
| 50 | + return sprintf( "Took %6.2fms",
|
| 51 | + $pertrial );
|
| 52 | + }
|
| 53 | +
|
| 54 | + private function benchLoadedHooks( $trials = 1 ) {
|
| 55 | + global $wgHooks;
|
| 56 | + $wgHooks['Test'][] = array( $this, 'test' );
|
| 57 | +
|
| 58 | + $start = wfTime();
|
| 59 | + for ( $i = 0; $i < $trials; $i++ ) {
|
| 60 | + wfRunHooks( 'Test' );
|
| 61 | + }
|
| 62 | + $delta = wfTime() - $start;
|
| 63 | + $pertrial = $delta / $trials;
|
| 64 | + return sprintf( "Took %6.2fms",
|
| 65 | + $pertrial );
|
| 66 | + }
|
| 67 | +
|
| 68 | + public function test() {
|
| 69 | + return true;
|
| 70 | + }
|
| 71 | +}
|
| 72 | +
|
| 73 | +$maintClass = "BenchmarkHooks";
|
| 74 | +require_once( RUN_MAINTENANCE_IF_MAIN );
|