?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常见数据库操作技巧汇总》