- strpos: documentation ( source)
- microtime: documentation ( source)
- str_repeat: documentation ( source)
- stripos: documentation ( source)
- number_format: documentation ( source)
<?php
function mt($start=null){
if ($start === null) return microtime(true);
return number_format(microtime(true)-$start, 4);
}
$str_100k = str_repeat('a', 102400).str_repeat('b', 1024);
$str = $str_100k;
$needle = 'bbbbbbbbb';
$start = mt();
for ($i=0; $i<500; $i++) $j = strpos($str, $needle); // strpos
$t_strpos = mt($start);
#echo "\t".mt($start);
$start = mt();
for ($i=0; $i<500; $i++) $j = stripos($str, $needle); // stripos
$t_stripos = mt($start);
#echo "\t".mt($start);
echo number_format($t_stripos/$t_strpos, 1);