MediaWiki REL1_28
benchmarkHooks.php
Go to the documentation of this file.
1<?php
24require_once __DIR__ . '/Benchmarker.php';
25
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';
87require_once RUN_MAINTENANCE_IF_MAIN;
$maintClass
Maintenance script that benchmarks MediaWiki hooks.
benchHooks( $trials=10)
__construct()
Default constructor.
execute()
Do the actual work.
Base class for benchmark scripts.
addDescription( $text)
Set the description text.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition hooks.txt:1752
$wgHooks['ArticleShow'][]
Definition hooks.txt:110
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:37
require_once RUN_MAINTENANCE_IF_MAIN