MediaWiki REL1_30
bench_strtr_str_replace.php
Go to the documentation of this file.
1<?php
26require_once __DIR__ . '/Benchmarker.php';
27
28function bfNormalizeTitleStrTr( $str ) {
29 return strtr( $str, '_', ' ' );
30}
31
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
73$maintClass = 'BenchStrtrStrReplace';
74require_once RUN_MAINTENANCE_IF_MAIN;
bfNormalizeTitleStrTr( $str)
bfNormalizeTitleStrReplace( $str)
Maintenance script that benchmarks for strtr() vs str_replace().
__construct()
Default constructor.
execute()
Do the actual work.
Base class for benchmark scripts.
bench(array $benchs)
addDescription( $text)
Set the description text.
require_once RUN_MAINTENANCE_IF_MAIN