r79755 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79754‎ | r79755 | r79756 >
Date:21:00, 6 January 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Add benchmark for bug 26605 Use strtr instead of str_replace when possible
Modified paths:
  • /trunk/phase3/maintenance/benchmarks/bench_strtr_str_replace.php (added) (history)

Diff [purge]

Index: trunk/phase3/maintenance/benchmarks/bench_strtr_str_replace.php
@@ -0,0 +1,30 @@
 2+<?php
 3+
 4+require_once( dirname( __FILE__ ) . '/Benchmarker.php' );
 5+class bench_strtr_str_replace extends Benchmarker {
 6+
 7+ public function __construct() {
 8+ parent::__construct();
 9+ $this->mDescription = "Benchmark for strtr() vs str_replace().";
 10+ }
 11+
 12+ public function execute() {
 13+ $this->bench( array(
 14+ array( 'function' => array( $this, 'benchstrtr' ) ),
 15+ array( 'function' => array( $this, 'benchstr_replace' ) ),
 16+ ));
 17+ print $this->getFormattedResults();
 18+ }
 19+
 20+ function benchstrtr() {
 21+ strtr( "[[MediaWiki:Some_random_test_page]]", "_", "" );
 22+ }
 23+
 24+ function benchstr_replace() {
 25+ str_replace( "_", " ", "[[MediaWiki:Some_random_test_page]]");
 26+ }
 27+
 28+}
 29+
 30+$maintClass = 'bench_strtr_str_replace';
 31+require_once( DO_MAINTENANCE );
Property changes on: trunk/phase3/maintenance/benchmarks/bench_strtr_str_replace.php
___________________________________________________________________
Added: svn:eol-style
132 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r79854Fix & additions for strtr vs str_replace benchmarks (for bug 26605 discussion)...brion01:10, 8 January 2011

Comments

#Comment by 😂 (talk | contribs)   21:08, 6 January 2011

Forgot an svn add?

#Comment by Nikerabbit (talk | contribs)   10:25, 7 January 2011

Add what? FYI: for me the 100 iterations does not show any speed difference.

#Comment by Reedy (talk | contribs)   15:26, 7 January 2011

Chad didn't notice the benchmark was added before

Also minimal difference for me also. Noted on bug

Status & tagging log