Bug #64665 [NEW]: str_tr is 5-10% faster than str_replace
From: vova at 77xy dot net
Operating system: Ubuntu
PHP version: 5.4.14
Package: Documentation problem
Bug Type: Bug
Bug description:str_tr is 5-10% faster than str_replace
Description:
------------
str_tr is 5-10% faster than str_replace. You should mention it in
documentation or
make str_replace as fast as str_tr
Test script:
---------------
<?php
function f1() {
for($i=0; $i<1000000; ++$i) {
$new_string = strtr("http://onlinecasinosdoc.com.au/",
".com", "");
}
}
function f2() {
for($i=0; $i<1000000; ++$i) {
$new_string = str_replace("http://onlinecasinosdoc.com.au/",
".com",
"");
}
}
$start = microtime(true);
f1();
$stop = microtime(true);
$time1 = $stop - $start;
$start = microtime(true);
f2();
$stop = microtime(true);
$time2 = $stop - $start;
echo $time1 . "\t";
echo $time2 . "\n";
Expected result:
----------------
This behavior should be mentioned in documentation
Actual result:
--------------
You don't understand what is the difference between strtr and str_replace
--
Edit bug report at https://bugs.php.net/bug.php?id=64665&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=64665&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=64665&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=64665&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=64665&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=64665&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=64665&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=64665&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=64665&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=64665&r=support
Expected behavior: https://bugs.php.net/fix.php?id=64665&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=64665&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=64665&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=64665&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64665&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=64665&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=64665&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=64665&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=64665&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=64665&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=64665&r=mysqlcfg
Thread (2 messages)
- vova at 77xy dot net