<?php
$cnt = 1000;
$strs = [
'empty' => '',
'short' => 'zluty kun',
'short_with_uc' => 'zluty Kun',
'long' => str_repeat('this is about 10000 chars long string', 270),
'long_with_uc' => str_repeat('this is about 10000 chars long String', 270),
'short_utf8' => 'žlutý kůň',
'short_utf8_with_uc' => 'Žlutý kŮň',
];
foreach ($strs as $k => $str) {
$a1 = microtime(true);
for($i=0; $i < $cnt; ++$i){
$res = strtolower($str);
}
$t1 = microtime(true) - $a1;
// echo 'it took ' . round($t1 * 1000, 3) . ' ms for ++$i'."\n";
$a2 = microtime(true);
for($i=0; $i < $cnt; $i++){
$res = mb_strtolower($str);
}
$t2 = microtime(true) - $a2;
// echo 'it took ' . round($t2 * 1000, 3) . ' ms for $i++'."\n";
echo 'strtolower is '.round($t2/$t1, 2).'x faster than mb_strtolower for ' . $k . "\n\n";
}
preferences:
35.18 ms | 402 KiB | 5 Q