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
19 * @ingroup Maintenance
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" );
47 $this->output( "\n" );
50 private function benchHooks( $trials = 1 ) {
52 for ( $i = 0; $i < $trials; $i++
) {
55 $delta = wfTime() - $start;
56 $pertrial = $delta / $trials;
57 return sprintf( "Took %6.2fms",
61 public function test() {
66 $maintClass = "BenchmarkHooks";
67 require_once( RUN_MAINTENANCE_IF_MAIN
);