3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
22 require_once( dirname( __FILE__
) . '/Benchmarker.php' );
24 class BenchmarkHooks
extends Benchmarker
{
26 public function __construct() {
27 parent
::__construct();
28 $this->mDescription
= 'Benchmark MediaWiki Hooks.';
31 public function execute() {
33 $wgHooks['Test'] = array();
35 $time = $this->benchHooks();
36 $this->output( 'Empty hook: ' . $time . "\n" );
38 $wgHooks['Test'][] = array( $this, 'test' );
39 $time = $this->benchHooks();
40 $this->output( 'Loaded (one) hook: ' . $time . "\n" );
42 for( $i = 0; $i < 9; $i++
) {
43 $wgHooks['Test'][] = array( $this, 'test' );
45 $time = $this->benchHooks();
46 $this->output( 'Loaded (ten) hook: ' . $time . "\n" );
48 for( $i = 0; $i < 90; $i++
) {
49 $wgHooks['Test'][] = array( $this, 'test' );
51 $time = $this->benchHooks();
52 $this->output( 'Loaded (one hundred) hook: ' . $time . "\n" );
53 $this->output( "\n" );
60 private function benchHooks( $trials = 10 ) {
62 for ( $i = 0; $i < $trials; $i++
) {
65 $delta = wfTime() - $start;
66 $pertrial = $delta / $trials;
67 return sprintf( "Took %6.2fs",
74 public function test() {
79 $maintClass = 'BenchmarkHooks';
80 require_once( RUN_MAINTENANCE_IF_MAIN
);