Merge "Add raw HTML output functionality"
[mediawiki.git] / maintenance / benchmarks / bench_strtr_str_replace.php
blobbd21b186a30fefc469b2cd21c1b081c2825cc449
1 <?php
2 /**
3 * Benchmark for strtr() vs str_replace().
5 * This come from r75429 message.
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.
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.
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
22 * @file
23 * @ingroup Benchmark
26 require_once __DIR__ . '/Benchmarker.php';
28 function bfNormalizeTitleStrTr( $str ) {
29 return strtr( $str, '_', ' ' );
32 function bfNormalizeTitleStrReplace( $str ) {
33 return str_replace( '_', ' ', $str );
36 /**
37 * Maintenance script that benchmarks for strtr() vs str_replace().
39 * @ingroup Benchmark
41 class bench_strtr_str_replace extends Benchmarker {
43 public function __construct() {
44 parent::__construct();
45 $this->mDescription = "Benchmark for strtr() vs str_replace().";
48 public function execute() {
49 $this->bench( array(
50 array( 'function' => array( $this, 'benchstrtr' ) ),
51 array( 'function' => array( $this, 'benchstr_replace' ) ),
52 array( 'function' => array( $this, 'benchstrtr_indirect' ) ),
53 array( 'function' => array( $this, 'benchstr_replace_indirect' ) ),
54 ));
55 print $this->getFormattedResults();
58 function benchstrtr() {
59 strtr( "[[MediaWiki:Some_random_test_page]]", "_", " " );
62 function benchstr_replace() {
63 str_replace( "_", " ", "[[MediaWiki:Some_random_test_page]]");
67 function benchstrtr_indirect() {
68 bfNormalizeTitleStrTr( "[[MediaWiki:Some_random_test_page]]" );
71 function benchstr_replace_indirect() {
72 bfNormalizeTitleStrReplace( "[[MediaWiki:Some_random_test_page]]" );
77 $maintClass = 'bench_strtr_str_replace';
78 require_once RUN_MAINTENANCE_IF_MAIN;