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 // @codeCoverageIgnoreStart
25 require_once __DIR__
. '/../includes/Benchmarker.php';
26 // @codeCoverageIgnoreEnd
29 * Maintenance script that benchmarks %MediaWiki hooks.
33 class BenchmarkHooks
extends Benchmarker
{
35 protected $defaultCount = 10;
37 public function __construct() {
38 parent
::__construct();
39 $this->addDescription( 'Benchmark MediaWiki Hooks.' );
42 public function execute() {
44 'Loaded 0 hooks' => 0,
46 'Loaded 10 hooks' => 10,
47 'Loaded 100 hooks' => 100,
50 $hookContainer = $this->getHookContainer();
51 foreach ( $cases as $label => $load ) {
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 );
69 public function test() {
74 // @codeCoverageIgnoreStart
75 $maintClass = BenchmarkHooks
::class;
76 require_once RUN_MAINTENANCE_IF_MAIN
;
77 // @codeCoverageIgnoreEnd