3 require_once( dirname( __FILE__
) . '/Benchmarker.php' );
5 function bfNormalizeTitleStrTr( $str ) {
6 return strtr( $str, '_', ' ' );
9 function bfNormalizeTitleStrReplace( $str ) {
10 return str_replace( '_', ' ', $str );
13 class bench_strtr_str_replace
extends Benchmarker
{
15 public function __construct() {
16 parent
::__construct();
17 $this->mDescription
= "Benchmark for strtr() vs str_replace().";
20 public function execute() {
22 array( 'function' => array( $this, 'benchstrtr' ) ),
23 array( 'function' => array( $this, 'benchstr_replace' ) ),
24 array( 'function' => array( $this, 'benchstrtr_indirect' ) ),
25 array( 'function' => array( $this, 'benchstr_replace_indirect' ) ),
27 print $this->getFormattedResults();
30 function benchstrtr() {
31 strtr( "[[MediaWiki:Some_random_test_page]]", "_", " " );
34 function benchstr_replace() {
35 str_replace( "_", " ", "[[MediaWiki:Some_random_test_page]]");
39 function benchstrtr_indirect() {
40 bfNormalizeTitleStrTr( "[[MediaWiki:Some_random_test_page]]" );
43 function benchstr_replace_indirect() {
44 bfNormalizeTitleStrReplace( "[[MediaWiki:Some_random_test_page]]" );
49 $maintClass = 'bench_strtr_str_replace';
50 require_once( RUN_MAINTENANCE_IF_MAIN
);