?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";
更多關于PHP相關內容感興趣的讀者可查看本站專題:《php常用函數與技巧總結》、《php字符串(string)用法總結》、《PHP數組(Array)操作技巧大全》、《PHP基本語法入門教程》、《php+mysql數據庫操作入門教程》及《php常見數據庫操作技巧匯總》