| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
require_once __DIR__ . '/../includes/Benchmarker.php'; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
class BenchmarkHooks extends Benchmarker { |
| 34 |
|
| 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 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
public function test() { |
| 70 |
return true; |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
$maintClass = BenchmarkHooks::class; |
| 76 |
require_once RUN_MAINTENANCE_IF_MAIN; |
| 77 |
|