MediaWiki master
benchmarkHooks.php
Go to the documentation of this file.
1<?php
11
12// @codeCoverageIgnoreStart
13require_once __DIR__ . '/../includes/Benchmarker.php';
14// @codeCoverageIgnoreEnd
15
23 protected $defaultCount = 10;
24
25 public function __construct() {
26 parent::__construct();
27 $this->addDescription( 'Benchmark MediaWiki Hooks.' );
28 }
29
30 public function execute() {
31 $cases = [
32 'Loaded 0 hooks' => 0,
33 'Loaded 1 hook' => 1,
34 'Loaded 10 hooks' => 10,
35 'Loaded 100 hooks' => 100,
36 ];
37 $benches = [];
38 $hookContainer = $this->getHookContainer();
39 foreach ( $cases as $label => $load ) {
40 $benches[$label] = [
41 'setup' => function () use ( $load, $hookContainer ) {
42 for ( $i = 1; $i <= $load; $i++ ) {
43 $hookContainer->register( 'Test', [ $this, 'test' ] );
44 }
45 },
46 'function' => static function () use ( $hookContainer ) {
47 $hookContainer->run( 'Test' );
48 }
49 ];
50 }
51 $this->bench( $benches );
52 }
53
57 public function test() {
58 return true;
59 }
60}
61
62// @codeCoverageIgnoreStart
63$maintClass = BenchmarkHooks::class;
64require_once RUN_MAINTENANCE_IF_MAIN;
65// @codeCoverageIgnoreEnd
$maintClass
Maintenance script that benchmarks MediaWiki hooks.
__construct()
Default constructor.
execute()
Do the actual work.
Base class for benchmark scripts.
getHookContainer()
Get a HookContainer, for running extension hooks or for hook metadata.
addDescription( $text)
Set the description text.