|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64665 str_tr is 5-10% faster than str_replace
Submitted: 2013-04-18 08:37 UTC Modified: 2013-04-18 17:45 UTC
From: vova at 77xy dot net Assigned:
Status: Wont fix Package: Documentation problem
PHP Version: 5.4.14 OS: Ubuntu
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: vova at 77xy dot net
New email:
PHP Version: OS:


 [2013-04-18 08:37 UTC] vova at 77xy dot net
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:
function f1() {
  for($i=0; $i<1000000; ++$i) {
    $new_string = strtr("", ".com", "");
function f2() {
  for($i=0; $i<1000000; ++$i) {
    $new_string = str_replace("", ".com", "");
$start = microtime(true);
$stop = microtime(true);
$time1 = $stop - $start;
$start = microtime(true);
$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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-04-18 17:45 UTC]
-Status: Open +Status: Wont fix
 [2013-04-18 17:45 UTC]
They do different things — which one you use should be based on what you need to do, not micro-optimisation.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 14:01:32 2024 UTC