3 * Benchmark %MediaWiki hooks.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 require_once __DIR__
. '/Benchmarker.php';
27 * Maintenance script that benchmarks %MediaWiki hooks.
31 class BenchmarkHooks
extends Benchmarker
{
32 public function __construct() {
33 parent
::__construct();
34 $this->addDescription( 'Benchmark MediaWiki Hooks.' );
37 public function execute() {
39 $wgHooks['Test'] = [];
41 $time = $this->benchHooks();
42 $this->output( 'Empty hook: ' . $time . "\n" );
44 $wgHooks['Test'][] = [ $this, 'test' ];
45 $time = $this->benchHooks();
46 $this->output( 'Loaded (one) hook: ' . $time . "\n" );
48 for ( $i = 0; $i < 9; $i++
) {
49 $wgHooks['Test'][] = [ $this, 'test' ];
51 $time = $this->benchHooks();
52 $this->output( 'Loaded (ten) hook: ' . $time . "\n" );
54 for ( $i = 0; $i < 90; $i++
) {
55 $wgHooks['Test'][] = [ $this, 'test' ];
57 $time = $this->benchHooks();
58 $this->output( 'Loaded (one hundred) hook: ' . $time . "\n" );
59 $this->output( "\n" );
66 private function benchHooks( $trials = 10 ) {
67 $start = microtime( true );
68 for ( $i = 0; $i < $trials; $i++
) {
71 $delta = microtime( true ) - $start;
72 $pertrial = $delta / $trials;
74 return sprintf( "Took %6.3fms",
81 public function test() {
86 $maintClass = 'BenchmarkHooks';
87 require_once RUN_MAINTENANCE_IF_MAIN
;