MediaWiki  master
benchmarkStringReplacement.php
Go to the documentation of this file.
1 <?php
22 require_once __DIR__ . '/Benchmarker.php';
23 
30  protected $defaultCount = 10000;
31  private $input = 'MediaWiki:Some_random_test_page';
32 
33  public function __construct() {
34  parent::__construct();
35  $this->addDescription( 'Benchmark for string replacement methods.' );
36  }
37 
38  public function execute() {
39  $this->bench( [
40  'strtr' => [ $this, 'bench_strtr' ],
41  'str_replace' => [ $this, 'bench_str_replace' ],
42  ] );
43  }
44 
45  protected function bench_strtr() {
46  strtr( $this->input, "_", " " );
47  }
48 
49  protected function bench_str_replace() {
50  str_replace( "_", " ", $this->input );
51  }
52 }
53 
54 $maintClass = BenchmarkStringReplacement::class;
55 require_once RUN_MAINTENANCE_IF_MAIN;
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
bench(array $benchs)
Definition: Benchmarker.php:50
addDescription( $text)
Set the description text.
Maintenance script that benchmarks string replacement methods.
Base class for benchmark scripts.
Definition: Benchmarker.php:40