結果:
run times :1000000
preg_match time: 2.2464230061 seconds.
stristr time: 3.1119530201 seconds.
39% improvement.
<?php
function timeStamp() {
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$startTime = timeStamp();
$j = 1000000;
for($i=$j; $i > 1; $i--) {
$test = preg_match("/com/i", "PHP is the web scripting lan.comguage of choice.");
}
echo "run times :".$j."<br>";
$splitTime = timeStamp();
$splitTimeecho = round($splitTime - $startTime,10);
echo "preg_match time: ".$splitTimeecho." seconds.";
// Do some more things here
for($i=$j; $i > 1; $i--) {
$test2 = stristr("PHP is the web scripting lan.comguage of choice.", 'com');
}
$endTime = timeStamp();
$totalTime = round($endTime - $splitTime,10);
echo "<br>stristr time: ".$totalTime." seconds.<br>";
echo round(($totalTime / $splitTimeecho) * 100) - 100 . "% improvement.";
?>
沒有留言:
張貼留言