Debian Codegraph @

maintenance/benchmarks/benchmarkHooks.php

raw symbols SCIP
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 // @codeCoverageIgnoreStart
25 require_once __DIR__ . '/../includes/Benchmarker.php';
26 // @codeCoverageIgnoreEnd
27
28 /**
29 * Maintenance script that benchmarks %MediaWiki hooks.
30 *
31 * @ingroup Benchmark
32 */
33 class BenchmarkHooks extends Benchmarker {
34 /** @inheritDoc */
35 protected $defaultCount = 10;
36
37 public function __construct() {
38 parent::__construct();
39 $this->addDescription( 'Benchmark MediaWiki Hooks.' );
40 }
41
42 public function execute() {
43 $cases = [
44 'Loaded 0 hooks' => 0,
45 'Loaded 1 hook' => 1,
46 'Loaded 10 hooks' => 10,
47 'Loaded 100 hooks' => 100,
48 ];
49 $benches = [];
50 $hookContainer = $this->getHookContainer();
51 foreach ( $cases as $label => $load ) {
52 $benches[$label] = [
53 'setup' => function () use ( $load, $hookContainer ) {
54 for ( $i = 1; $i <= $load; $i++ ) {
55 $hookContainer->register( 'Test', [ $this, 'test' ] );
56 }
57 },
58 'function' => static function () use ( $hookContainer ) {
59 $hookContainer->run( 'Test' );
60 }
61 ];
62 }
63 $this->bench( $benches );
64 }
65
66 /**
67 * @return bool
68 */
69 public function test() {
70 return true;
71 }
72 }
73
74 // @codeCoverageIgnoreStart
75 $maintClass = BenchmarkHooks::class;
76 require_once RUN_MAINTENANCE_IF_MAIN;
77 // @codeCoverageIgnoreEnd