MediaWiki master
benchmarkHooks.php
Go to the documentation of this file.
1<?php
24// @codeCoverageIgnoreStart
25require_once __DIR__ . '/../includes/Benchmarker.php';
26// @codeCoverageIgnoreEnd
27
33class BenchmarkHooks extends Benchmarker {
35 protected $defaultCount = 10;
36
37 public function __construct() {
38 parent::__construct();
39 $this->addDescription( 'Benchmark MediaWiki Hooks.' );
40 }
41
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,
48 ];
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' ] );
56 }
57 },
58 'function' => static function () use ( $hookContainer ) {
59 $hookContainer->run( 'Test' );
60 }
61 ];
62 }
63 $this->bench( $benches );
64 }
65
69 public function test() {
70 return true;
71 }
72}
73
74// @codeCoverageIgnoreStart
75$maintClass = BenchmarkHooks::class;
76require_once RUN_MAINTENANCE_IF_MAIN;
77// @codeCoverageIgnoreEnd
$maintClass
Maintenance script that benchmarks MediaWiki hooks.