7 require_once( dirname( __FILE__
) . '/Benchmarker.php' );
9 function bfNormalizeTitleStrTr( $str ) {
10 return strtr( $str, '_', ' ' );
13 function bfNormalizeTitleStrReplace( $str ) {
14 return str_replace( '_', ' ', $str );
17 class bench_strtr_str_replace
extends Benchmarker
{
19 public function __construct() {
20 parent
::__construct();
21 $this->mDescription
= "Benchmark for strtr() vs str_replace().";
24 public function execute() {
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' ) ),
31 print $this->getFormattedResults();
34 function benchstrtr() {
35 strtr( "[[MediaWiki:Some_random_test_page]]", "_", " " );
38 function benchstr_replace() {
39 str_replace( "_", " ", "[[MediaWiki:Some_random_test_page]]");
43 function benchstrtr_indirect() {
44 bfNormalizeTitleStrTr( "[[MediaWiki:Some_random_test_page]]" );
47 function benchstr_replace_indirect() {
48 bfNormalizeTitleStrReplace( "[[MediaWiki:Some_random_test_page]]" );
53 $maintClass = 'bench_strtr_str_replace';
54 require_once( RUN_MAINTENANCE_IF_MAIN
);