PHP strtr与str_replace函数性能简单测试
来源:互联网 发布:搭建阿里云服务器 编辑:程序博客网 时间:2024/06/09 20:09
strtr与str_replace函数性能,很简单的一个测试,只是简单的测下,供参考,代码如下:
<?phprequire_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";
结果如下:
那个正则替换的那个就不测了,应该是赶不上这两个的。
0 0
- PHP strtr与str_replace函数性能简单测试
- PHP替换字符串函数strtr()和str_replace()
- PHP str_replace() 函数 & strtr() 函数 的常见用法
- 关于str_replace和strtr函数
- strtr与str_replace的区别
- PHP中strtr和str_replace比较
- PHP中strtr()和str_replace()的区别
- php中strtr和str_replace的坑
- 关于PHP中的strtr和str_replace使用
- php中strtr和str_replace的坑
- PHP strtr() 函数
- php函数strtr
- PHP字符串函数strtr
- 比较strtr, str_replace和preg_replace三个函数的效率
- PHP 字符串替换 substr_replace 与 str_replace 函数
- PHP函数:str_replace()
- PHP str_replace() 函数实例教程
- PHP str_replace() 函数
- iphone之利用Masonry框架为组件创建约束
- 大数据量时Mysql的优化要点[转]
- Android ListView的addHeaderView与addFooterView的详解
- 利用ViewPager、PagerTabStrip实现滚动导航
- HDOJ1010.Tempter of the Bone
- PHP strtr与str_replace函数性能简单测试
- App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Te
- 动态访问某个方法
- android 开发 小技巧
- 利用border-radius属性写个简单的左右内弧,上下外弧的框
- 【必看】用户画像数据建模方法
- 小马哥---高仿红米note 刷机 主板型号T7203主板图与开机识别图 6572芯片
- 深入hibernate的三种状态
- Cocos2d-swift V3.x 中的update方法