?php
require_once('Timer.php');
$target = 'qwertyuiop[]asdfghjkl;\'zxcvbnm,./qwertyuiop[]asdfghjkl;'zxcvbnm,./qwertyuiop[]asdfghjkl;\'zxcvbnm,./qwertyuiop[]asdfghjkl;'zxcvbnm,./qwertyuiop[]asdfghjkl;\'zxcvbnm,./qwertyuiop[]asdfghjkl;'zxcvbnm,./qwertyuiop[]asdfghjkl;\'zxcvbnm,./qwertyuiop[]asdfghjkl;'zxcvbnm,./qwertyuiop[]asdfghjkl;\'zxcvbnm,./qwertyuiop[]asdfghjkl;'zxcvbnm,./';
$count = isset($argv[1]) ? (int)$argv[1] : 1;
$needle = 'vb';
Timer::getInstance()->begin();
for($i = 0; $i $count; $i++) {
strtr($target, $needle, '*');
}
echo "strtr exec {$count} times used time: " . Timer::getInstance()->end()->gone() . " sec.\n";
//----------------------------------------------------------------------------------------------
Timer::getInstance()->begin();
for($i = 0; $i $count; $i++) {
str_replace($needle, '*', $target);
}
echo "str_replace exec {$count} times used time: " . Timer::getInstance()->end()->gone() . " sec.\n";
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php常用函數(shù)與技巧總結(jié)》、《php字符串(string)用法總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《PHP基本語法入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》