Skip to content

Instantly share code, notes, and snippets.

@danemacmillan
Created January 15, 2014 00:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danemacmillan/8428801 to your computer and use it in GitHub Desktop.
Save danemacmillan/8428801 to your computer and use it in GitHub Desktop.
PHP benchmark performance: `strlen` vs `mb_strlen`
<?php
$iterations = 10000;
$str = 'The speed of calculating the length of this string will be performed.';
function a($s)
{
$l = strlen($s);
}
function b($s)
{
$l = mb_strlen($s);
}
$a_time = 0;
$i = 0;
$a_start = microtime(true);
while ($i <= $iterations) {
a($str);
$i++;
}
$a_end = microtime(true);
$b_time = 0;
$i = 0;
$b_start = microtime(true);
while ($i <= $iterations) {
b($str);
$i++;
}
$b_end = microtime(true);
echo 'strlen: ' . ($a_end - $a_start) . '<br />';
echo 'mb_strlen: ' . ($b_end - $b_start);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment