note 55339 deleted from function.strtolower by nlopess
| From: | nlopess@php.net | Date: | Fri, 18 Nov 2005 19:25:06 +0000 |
| Subject: | note 55339 deleted from function.strtolower by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-98770@lists.php.net to get a copy of this message | ||
Note Submitter: jbr at ya-right dot com
----
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