MediaWiki master
benchmarkHooks.php
Go to the documentation of this file.
1<?php
25
26// @codeCoverageIgnoreStart
27require_once __DIR__ . '/../includes/Benchmarker.php';
28// @codeCoverageIgnoreEnd
29
37 protected $defaultCount = 10;
38
39 public function __construct() {
40 parent::__construct();
41 $this->addDescription( 'Benchmark MediaWiki Hooks.' );
42 }
43
44 public function execute() {
45 $cases = [
46 'Loaded 0 hooks' => 0,
47 'Loaded 1 hook' => 1,
48 'Loaded 10 hooks' => 10,
49 'Loaded 100 hooks' => 100,
50 ];
51 $benches = [];
52 $hookContainer = $this->getHookContainer();
53 foreach ( $cases as $label => $load ) {
54 $benches[$label] = [
55 'setup' => function () use ( $load, $hookContainer ) {
56 for ( $i = 1; $i <= $load; $i++ ) {
57 $hookContainer->register( 'Test', [ $this, 'test' ] );
58 }
59 },
60 'function' => static function () use ( $hookContainer ) {
61 $hookContainer->run( 'Test' );
62 }
63 ];
64 }
65 $this->bench( $benches );
66 }
67
71 public function test() {
72 return true;
73 }
74}
75
76// @codeCoverageIgnoreStart
77$maintClass = BenchmarkHooks::class;
78require_once RUN_MAINTENANCE_IF_MAIN;
79// @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.