MediaWiki  REL1_31
bench_strtr_str_replace.php
Go to the documentation of this file.
1 <?php
26 require_once __DIR__ . '/Benchmarker.php';
27 
28 function bfNormalizeTitleStrTr( $str ) {
29  return strtr( $str, '_', ' ' );
30 }
31 
32 function bfNormalizeTitleStrReplace( $str ) {
33  return str_replace( '_', ' ', $str );
34 }
35 
42  public function __construct() {
43  parent::__construct();
44  $this->addDescription( 'Benchmark for strtr() vs str_replace().' );
45  }
46 
47  public function execute() {
48  $this->bench( [
49  [ 'function' => [ $this, 'benchstrtr' ] ],
50  [ 'function' => [ $this, 'benchstr_replace' ] ],
51  [ 'function' => [ $this, 'benchstrtr_indirect' ] ],
52  [ 'function' => [ $this, 'benchstr_replace_indirect' ] ],
53  ] );
54  }
55 
56  protected function benchstrtr() {
57  strtr( "[[MediaWiki:Some_random_test_page]]", "_", " " );
58  }
59 
60  protected function benchstr_replace() {
61  str_replace( "_", " ", "[[MediaWiki:Some_random_test_page]]" );
62  }
63 
64  protected function benchstrtr_indirect() {
65  bfNormalizeTitleStrTr( "[[MediaWiki:Some_random_test_page]]" );
66  }
67 
68  protected function benchstr_replace_indirect() {
69  bfNormalizeTitleStrReplace( "[[MediaWiki:Some_random_test_page]]" );
70  }
71 }
72 
74 require_once RUN_MAINTENANCE_IF_MAIN;
BenchStrtrStrReplace\__construct
__construct()
Default constructor.
Definition: bench_strtr_str_replace.php:42
bfNormalizeTitleStrTr
bfNormalizeTitleStrTr( $str)
Definition: bench_strtr_str_replace.php:28
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:291
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
$maintClass
$maintClass
Definition: bench_strtr_str_replace.php:73
Benchmarker\bench
bench(array $benchs)
Definition: Benchmarker.php: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:37
BenchStrtrStrReplace\benchstrtr
benchstrtr()
Definition: bench_strtr_str_replace.php:56
BenchStrtrStrReplace
Maintenance script that benchmarks for strtr() vs str_replace().
Definition: bench_strtr_str_replace.php:41
BenchStrtrStrReplace\execute
execute()
Do the actual work.
Definition: bench_strtr_str_replace.php:47
bfNormalizeTitleStrReplace
bfNormalizeTitleStrReplace( $str)
Definition: bench_strtr_str_replace.php:32
Benchmarker
Base class for benchmark scripts.
Definition: Benchmarker.php:40
BenchStrtrStrReplace\benchstr_replace_indirect
benchstr_replace_indirect()
Definition: bench_strtr_str_replace.php:68
BenchStrtrStrReplace\benchstrtr_indirect
benchstrtr_indirect()
Definition: bench_strtr_str_replace.php:64
BenchStrtrStrReplace\benchstr_replace
benchstr_replace()
Definition: bench_strtr_str_replace.php:60
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:56