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