MediaWiki  1.29.1
benchmarkHooks.php
Go to the documentation of this file.
1 <?php
24 require_once __DIR__ . '/Benchmarker.php';
25 
31 class BenchmarkHooks extends Benchmarker {
32  public function __construct() {
33  parent::__construct();
34  $this->addDescription( 'Benchmark MediaWiki Hooks.' );
35  }
36 
37  public function execute() {
39  $wgHooks['Test'] = [];
40 
41  $time = $this->benchHooks();
42  $this->output( 'Empty hook: ' . $time . "\n" );
43 
44  $wgHooks['Test'][] = [ $this, 'test' ];
45  $time = $this->benchHooks();
46  $this->output( 'Loaded (one) hook: ' . $time . "\n" );
47 
48  for ( $i = 0; $i < 9; $i++ ) {
49  $wgHooks['Test'][] = [ $this, 'test' ];
50  }
51  $time = $this->benchHooks();
52  $this->output( 'Loaded (ten) hook: ' . $time . "\n" );
53 
54  for ( $i = 0; $i < 90; $i++ ) {
55  $wgHooks['Test'][] = [ $this, 'test' ];
56  }
57  $time = $this->benchHooks();
58  $this->output( 'Loaded (one hundred) hook: ' . $time . "\n" );
59  $this->output( "\n" );
60  }
61 
66  private function benchHooks( $trials = 10 ) {
67  $start = microtime( true );
68  for ( $i = 0; $i < $trials; $i++ ) {
69  Hooks::run( 'Test' );
70  }
71  $delta = microtime( true ) - $start;
72  $pertrial = $delta / $trials;
73 
74  return sprintf( "Took %6.3fms",
75  $pertrial * 1000 );
76  }
77 
81  public function test() {
82  return true;
83  }
84 }
85 
86 $maintClass = 'BenchmarkHooks';
87 require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:287
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
BenchmarkHooks\__construct
__construct()
Default constructor.
Definition: benchmarkHooks.php:32
$time
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition: hooks.txt:1769
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
BenchmarkHooks\test
test()
Definition: benchmarkHooks.php:81
Benchmarker
Base class for benchmark scripts.
Definition: Benchmarker.php:36
BenchmarkHooks\execute
execute()
Do the actual work.
Definition: benchmarkHooks.php:37
BenchmarkHooks
Maintenance script that benchmarks MediaWiki hooks.
Definition: benchmarkHooks.php:31
$wgHooks
$wgHooks['ArticleShow'][]
Definition: hooks.txt:110
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:373
$maintClass
$maintClass
Definition: benchmarkHooks.php:86
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131
BenchmarkHooks\benchHooks
benchHooks( $trials=10)
Definition: benchmarkHooks.php:66