PHP中的stristr(),strstr(),strpos()速度比较 | ||
测速代码: <?php function getmicrotime() { list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } $time_start = getmicrotime(); $string="xxxddxx"; $find="d"; for ($i=0;$i<300000;$i++) { if (stristr($string,$find))//if (strstr($string,$find)) or if (strpos($string,$find)) {} } $time_end = getmicrotime(); echo $time_end-$time_start; ?> [/php] stristr() 第一次:2.74142408371 第二次:2.52075314522 第三次:2.52766990662 strstr() 第一次:1.43941402435 第二次:1.44914388657 第三次:1.51285290718 strpos() 第一次:1.42109084129 第二次:1.40254187584 第三次:1.38609910011 ---------------------------------- 可以看出,stristr在进行判断某一字符(串)是否存在于另一字符(串)时候,速度明显慢于另外两个。。 stristr对大小写不敏感的 strstr对大小写敏感 strpos不能判断是否有特殊字符(包括中文字符) 呵呵,以后用的时候记得选择好啦。。 |
最后
以上就是迷人饼干最近收集整理的关于PHP中的stristr(),strstr(),strpos()速度比较的全部内容,更多相关PHP中内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复