Localisation updates from https://translatewiki.net.
[mediawiki.git] / maintenance / benchmarks / benchmarkHooks.php
blobf01c551721f63a0fa00ca7a87bb88741a1a1834a
1 <?php
2 /**
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
20 * @file
21 * @ingroup Benchmark
24 // @codeCoverageIgnoreStart
25 require_once __DIR__ . '/../includes/Benchmarker.php';
26 // @codeCoverageIgnoreEnd
28 /**
29 * Maintenance script that benchmarks %MediaWiki hooks.
31 * @ingroup Benchmark
33 class BenchmarkHooks extends Benchmarker {
34 /** @inheritDoc */
35 protected $defaultCount = 10;
37 public function __construct() {
38 parent::__construct();
39 $this->addDescription( 'Benchmark MediaWiki Hooks.' );
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,
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' ] );
58 'function' => static function () use ( $hookContainer ) {
59 $hookContainer->run( 'Test' );
63 $this->bench( $benches );
66 /**
67 * @return bool
69 public function test() {
70 return true;
74 // @codeCoverageIgnoreStart
75 $maintClass = BenchmarkHooks::class;
76 require_once RUN_MAINTENANCE_IF_MAIN;
77 // @codeCoverageIgnoreEnd