phpcs: More require/include is not a function
[lhc/web/wiklou.git] / maintenance / benchmarks / benchmarkHooks.php
1 <?php
2 /**
3 * Benchmark %MediaWiki hooks.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup Benchmark
22 */
23
24 require_once __DIR__ . '/Benchmarker.php';
25
26 /**
27 * Maintenance script that benchmarks %MediaWiki hooks.
28 *
29 * @ingroup Benchmark
30 */
31 class BenchmarkHooks extends Benchmarker {
32
33 public function __construct() {
34 parent::__construct();
35 $this->mDescription = 'Benchmark MediaWiki Hooks.';
36 }
37
38 public function execute() {
39 global $wgHooks;
40 $wgHooks['Test'] = array();
41
42 $time = $this->benchHooks();
43 $this->output( 'Empty hook: ' . $time . "\n" );
44
45 $wgHooks['Test'][] = array( $this, 'test' );
46 $time = $this->benchHooks();
47 $this->output( 'Loaded (one) hook: ' . $time . "\n" );
48
49 for( $i = 0; $i < 9; $i++ ) {
50 $wgHooks['Test'][] = array( $this, 'test' );
51 }
52 $time = $this->benchHooks();
53 $this->output( 'Loaded (ten) hook: ' . $time . "\n" );
54
55 for( $i = 0; $i < 90; $i++ ) {
56 $wgHooks['Test'][] = array( $this, 'test' );
57 }
58 $time = $this->benchHooks();
59 $this->output( 'Loaded (one hundred) hook: ' . $time . "\n" );
60 $this->output( "\n" );
61 }
62
63 /**
64 * @param $trials int
65 * @return string
66 */
67 private function benchHooks( $trials = 10 ) {
68 $start = microtime( true );
69 for ( $i = 0; $i < $trials; $i++ ) {
70 wfRunHooks( 'Test' );
71 }
72 $delta = microtime( true ) - $start;
73 $pertrial = $delta / $trials;
74 return sprintf( "Took %6.3fms",
75 $pertrial * 1000 );
76 }
77
78 /**
79 * @return bool
80 */
81 public function test() {
82 return true;
83 }
84 }
85
86 $maintClass = 'BenchmarkHooks';
87 require_once RUN_MAINTENANCE_IF_MAIN;