note 111968 added to function.strtr
| From: | vova at 77xy dot net | Date: | Thu, 18 Apr 2013 08:33:24 +0000 |
| Subject: | note 111968 added to function.strtr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194526@lists.php.net to get a copy of this message | ||
str_tr is 5-10% faster than str_replace
<?php
function f1() {
for($i=0; $i<1000000; ++$i) {
$new_string = strtr("aboutdealers.com", ".com", "");
}
}
function f2() {
for($i=0; $i<1000000; ++$i) {
$new_string = str_replace("aboutdealers.com", ".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";
----
Server IP: 69.147.83.199
Probable Submitter: 178.214.195.66
----
Manual Page -- http://php.net/manual/en/function.strtr.php
Edit -- https://master.php.net/note/edit/111968
Del: integrated -- https://master.php.net/note/delete/111968/integrated
Del: useless -- https://master.php.net/note/delete/111968/useless
Del: bad code -- https://master.php.net/note/delete/111968/bad+code
Del: spam -- https://master.php.net/note/delete/111968/spam
Del: non-english -- https://master.php.net/note/delete/111968/non-english
Del: in docs -- https://master.php.net/note/delete/111968/in+docs
Del: other reasons-- https://master.php.net/note/delete/111968
Reject -- https://master.php.net/note/reject/111968
Search -- https://master.php.net/manage/user-notes.php