Merge "Added release notes for 'ContentHandler::runLegacyHooks' removal"
[mediawiki.git] / maintenance / benchmarks / bench_strtr_str_replace.php
blob156f8fcfe0820e28113efde3bbfd6fc08714b964
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 BenchStrtrStrReplace extends Benchmarker {
42 public function __construct() {
43 parent::__construct();
44 $this->addDescription( 'Benchmark for strtr() vs str_replace().' );
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 print $this->getFormattedResults();
57 function benchstrtr() {
58 strtr( "[[MediaWiki:Some_random_test_page]]", "_", " " );
61 function benchstr_replace() {
62 str_replace( "_", " ", "[[MediaWiki:Some_random_test_page]]" );
65 function benchstrtr_indirect() {
66 bfNormalizeTitleStrTr( "[[MediaWiki:Some_random_test_page]]" );
69 function benchstr_replace_indirect() {
70 bfNormalizeTitleStrReplace( "[[MediaWiki:Some_random_test_page]]" );
74 $maintClass = 'BenchStrtrStrReplace';
75 require_once RUN_MAINTENANCE_IF_MAIN;