Fix & additions for strtr vs str_replace benchmarks (for
bug 26605 discussion)
The strtr function in the benchmark was slightly artificially accelerated by replacing '_' with '' (empty) instead of ' ' (space), making the output string shorter and thus processing faster. This is now fixed, which makes the results slightly closer.
I also added 'indirect' functions to the benchmark, which instead of calling strtr/str_replace directly, call a global function which then calls them (equivalent to what we'd do if we turned the replaces into wf* global functions)
strtr() does appear to be slightly faster than str_replace() for this workload, but it's fairly modest and approximately the same as the overhead of a function call.
Results on my test box (MacBook Pro, 2.4GHz Core 2 Duo, Mac OS X 10.6.6, 64-bit PHP 5.3.4 built via MacPorts) with 10,000 reps:
$ php bench_strtr_str_replace.php --count=10000
10000 times: function bench_strtr_str_replace->benchstrtr() :
19.67ms ( 0.00ms each)
10000 times: function bench_strtr_str_replace->benchstr_replace() :
22.05ms ( 0.00ms each)
10000 times: function bench_strtr_str_replace->benchstrtr_indirect() :
22.53ms ( 0.00ms each)
10000 times: function bench_strtr_str_replace->benchstr_replace_indirect() :
26.29ms ( 0.00ms each)