note 55339 added to function.strtolower
| From: | jbr at ya-right dot com | Date: | Sun, 31 Jul 2005 10:17:37 +0000 |
| Subject: | note 55339 added to function.strtolower | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-92798@lists.php.net to get a copy of this message | ||
Any of these str... type functions (toupper, tolower) are very slow compared to strtr(). So if your
just wanting to convert a string to lower or upper case to use in maybe a custom PHP 4 stripos()
function or other type of function where converting the complete string to upper or lower is
important use strtr() instead...
test....
<?
$upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$lower = 'abcdefghijklmnopqrstuvwxyz';
$str = 'You can contribute your notes to the PHP manual from the comfort of your browser! Just
add your comment in the big field below, and, optionally, your email address or name in the little
one. After submission, your note will appear under the documentation as a part of the manual.';
$start = microtime(true);
$n = 0;
while ( $n < 10000 )
{
strtolower ( $str );
$n++;
}
$end = microtime(true);
$core = ( $end - $start );
$start = microtime(true);
$n = 0;
while ( $n < 10000 )
{
strtr ( $str, $upper, $lower );
$n++;
}
$end = microtime(true);
$custom = ( $end - $start );
echo 'core function strtolower() X 10000 took ' . $core . '<br />';
echo 'core function strtr() X 10000 took ' . $custom . '<br />';
$diff = ceil ( $core / $custom );
echo 'strtr() function is ( ' . $diff . 'X ) faster than the strtolower()
function!';
?>
John
----
Submitter IP: 12.160.245.96
----
Manual Page -- http://www.php.net/manual/en/function.strtolower.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55339
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55339&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55339&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55339&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55339&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55339&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55339&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55339&report=yes
Search -- http://master.php.net/manage/user-notes.php