Merge "Output PHP version before running PHPUnit tests"
[lhc/web/wiklou.git] / maintenance / benchmarks / bench_strtr_str_replace.php
1 <?php
2 /**
3 * Benchmark for strtr() vs str_replace().
4 *
5 * This come from r75429 message.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
21 *
22 * @file
23 * @ingroup Benchmark
24 */
25
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
36 /**
37 * Maintenance script that benchmarks for strtr() vs str_replace().
38 *
39 * @ingroup Benchmark
40 */
41 class BenchStrtrStrReplace extends Benchmarker {
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( array(
49 array( 'function' => array( $this, 'benchstrtr' ) ),
50 array( 'function' => array( $this, 'benchstr_replace' ) ),
51 array( 'function' => array( $this, 'benchstrtr_indirect' ) ),
52 array( 'function' => array( $this, 'benchstr_replace_indirect' ) ),
53 ) );
54 print $this->getFormattedResults();
55 }
56
57 function benchstrtr() {
58 strtr( "[[MediaWiki:Some_random_test_page]]", "_", " " );
59 }
60
61 function benchstr_replace() {
62 str_replace( "_", " ", "[[MediaWiki:Some_random_test_page]]" );
63 }
64
65 function benchstrtr_indirect() {
66 bfNormalizeTitleStrTr( "[[MediaWiki:Some_random_test_page]]" );
67 }
68
69 function benchstr_replace_indirect() {
70 bfNormalizeTitleStrReplace( "[[MediaWiki:Some_random_test_page]]" );
71 }
72 }
73
74 $maintClass = 'BenchStrtrStrReplace';
75 require_once RUN_MAINTENANCE_IF_MAIN;