Use __DIR__ instead of dirname( __FILE__ )
[lhc/web/wiklou.git] / maintenance / benchmarks / bench_strtr_str_replace.php
1 <?php
2 /**
3 * @file
4 * @ingroup Benchmark
5 */
6
7 require_once( __DIR__ . '/Benchmarker.php' );
8
9 function bfNormalizeTitleStrTr( $str ) {
10 return strtr( $str, '_', ' ' );
11 }
12
13 function bfNormalizeTitleStrReplace( $str ) {
14 return str_replace( '_', ' ', $str );
15 }
16
17 class bench_strtr_str_replace extends Benchmarker {
18
19 public function __construct() {
20 parent::__construct();
21 $this->mDescription = "Benchmark for strtr() vs str_replace().";
22 }
23
24 public function execute() {
25 $this->bench( array(
26 array( 'function' => array( $this, 'benchstrtr' ) ),
27 array( 'function' => array( $this, 'benchstr_replace' ) ),
28 array( 'function' => array( $this, 'benchstrtr_indirect' ) ),
29 array( 'function' => array( $this, 'benchstr_replace_indirect' ) ),
30 ));
31 print $this->getFormattedResults();
32 }
33
34 function benchstrtr() {
35 strtr( "[[MediaWiki:Some_random_test_page]]", "_", " " );
36 }
37
38 function benchstr_replace() {
39 str_replace( "_", " ", "[[MediaWiki:Some_random_test_page]]");
40 }
41
42
43 function benchstrtr_indirect() {
44 bfNormalizeTitleStrTr( "[[MediaWiki:Some_random_test_page]]" );
45 }
46
47 function benchstr_replace_indirect() {
48 bfNormalizeTitleStrReplace( "[[MediaWiki:Some_random_test_page]]" );
49 }
50
51 }
52
53 $maintClass = 'bench_strtr_str_replace';
54 require_once( RUN_MAINTENANCE_IF_MAIN );