explode,split,preg_split性能比较
三个函数都是用来对字符串进行分割,下面分几个实验来比较之间的性能。
1. explode与split比较
都用字符进行分割,执行10次
代码:
- for($num=0;$num<9;$num++)
- {
- $stime=microtime();
- for($i=0;$i<10000;$i++)
- {
- explode(',','hello,world');
- }
- $etime=microtime();
- printf("explode takes %f \n",$etime-$stime);
- }
- for($num=0;$num<9;$num++)
- {
- $stime=microtime();
- for($i=0;$i<10000;$i++)
- {
- split(',','hello,world');
- }
- $etime=microtime();
- printf("split takes %f \n",$etime-$stime);
- }
结果:
explode takes 0.009193
explode takes 0.007066
explode takes 0.007623
explode takes 0.005829
explode takes 0.005497
explode takes 0.005734
explode takes 0.005502
explode takes 0.005515
explode takes 0.005524
split takes 0.008976
split takes 0.008971
split takes 0.009030
split takes 0.009173
split takes 0.009913
split takes 0.012656
split takes 0.012153
split takes 0.009161
split takes 0.008948
结论:都用字符进行分割的情况下,explode性能优于split
split用正则进行分割:
代码:
- for($num=0;$num<9;$num++)
- {
- $stime=microtime();
- for($i=0;$i<10000;$i++)
- {
- explode(',','hello,world');
- }
- $etime=microtime();
- printf("explode takes %f \n",$etime-$stime);
- }
- for($num=0;$num<9;$num++)
- {
- $stime=microtime();
- for($i=0;$i<10000;$i++)
- {
- split('/,/','hello,world');
- }
- $etime=microtime();
- printf("split takes %f \n",$etime-$stime);
- }
结果:
explode takes 0.005649
explode takes 0.005719
explode takes 0.005792
explode takes 0.005975
explode takes 0.005723
explode takes 0.005812
explode takes 0.005860
explode takes 0.005756
explode takes 0.005835
split takes 0.005158
split takes 0.005170
split takes 0.005440
split takes 0.005402
split takes 0.005272
split takes 0.005434
split takes 0.006389
split takes 0.005414
split takes 0.005510
结论:在split使用正则分割的情况下,两者性能不相上下
2. split与preg_split比较
代码:
- for($num=0;$num<9;$num++)
- {
- $stime=microtime();
- for($i=0;$i<10000;$i++)
- {
- split('/,/','hello,world');
- }
- $etime=microtime();
- printf("split takes %f \n",$etime-$stime);
- }
- for($num=0;$num<9;$num++)
- {
- $stime=microtime();
- for($i=0;$i<10000;$i++)
- {
- preg_split("/,/","hello,world");
- }
- $etime=microtime();
- printf("preg_split takes %f \n",$etime-$stime);
- }
结果:
split takes 0.005381
split takes 0.005568
split takes 0.005107
split takes 0.005097
split takes 0.005444
split takes 0.005538
split takes 0.005095
split takes 0.005112
split takes 0.005087
preg_split takes 0.009364
preg_split takes 0.009568
preg_split takes 0.009037
preg_split takes 0.008957
preg_split takes 0.009021
preg_split takes 0.009656
preg_split takes 0.009038
preg_split takes 0.008962
preg_split takes 0.009412
结论:split性能优于preg_split
explode,split,preg_split性能比较的更多相关文章
- split(),preg_split()与explode()函数分析与介
split(),preg_split()与explode()函数分析与介 发布时间:2013-06-01 18:32:45 来源:尔玉毕业设计 评论:0 点击:965 split()函数可以实 ...
- Deprecated: Function split() is deprecated in ... 解决办法
本地测试的程序上传到服务器出现很多错误,Deprecated: Function split() is deprecated 查了原因是因为PHP的版本不同所导致的,本身程序开发的时候用的是PHP5 ...
- PHP:错误 Deprecated: Function split() is deprecated in ... 解决办法
PHP:错误 Deprecated: Function split() is deprecated in ... 解决办法 PHP5.3 split() 不建议使用的原因:PHP 5.3.0 之后的r ...
- php Function split() is deprecated 的解决办法
原文地址: http://www.cnblogs.com/mfryf/archive/2012/05/31/2527307.html php升级为5.3后,程序会报 Function split() ...
- 转义字符\(在hive+shell以及java中注意事项):正则表达式的转义字符为双斜线,split函数解析也是正则
转义字符 将后边字符转义,使特殊功能字符作为普通字符处理,或者普通字符转化为特殊功能字符. 各个语言中都用应用,如java.python.sql.hive.shell等等. 如sql中 "\ ...
- Hive表生成函数explode讲解
Hive中的表分析函数接受零个或多个输入,然后产生多列或多行输出. 1.explode函数 explode函数以array类型数据输入,然后对数组中的数据进行迭代,返回多行结果,一行一个数组元素值 A ...
- hive lateral view 与 explode详解
ref:https://blog.csdn.net/bitcarmanlee/article/details/51926530 1.explode hive wiki对于expolde的解释如下: e ...
- hive splict, explode, lateral view, concat_ws
hive> create table arrays (x array<string>) > row format delimited fields terminated by ...
- PHP之string之explode()函数使用
explode (PHP 4, PHP 5, PHP 7) explode - Split a string by string explode - 使用一个字符串分割另一个字符串 Descripti ...
随机推荐
- 测试webAPP时图标背景一片黑色
写了个web小程序,打包成APP后安装到手机里,在魅族手机里显示是正常的,但是在EMUI和MIUI中却显示一片黑色,搞了半天才发现原来是因为EMUI会自动给应用的图标裁剪圆角并加上背景色,背景色是系统 ...
- 对CPU做下性能测试
任务管理器里把pi.exe优先级调到“高” I5-4308U (2.80Ghz) PI-1M最佳成绩11.719秒(MACBOOK PRO 13inch,插电,电源选择高性能模式) G202 ...
- Amoeba+Mysql实现数据库读写分离
一.Amoeba 是什么 Amoeba(变形虫)项目,专注 分布式数据库 proxy 开发.座落与Client.DB Server(s)之间.对客户端透明.具有负载均衡.高可用性.sql过滤.读写分离 ...
- jQuery插件编写笔记
插件的种类: 1.封装对象方法的插件. 2.封装全局函数的插件. 3.选择器插件. *所有的对象方法都应当附加到jQuery.fn对象上,而所有的全局函数都应当附加到jQuery对象本身上. *在插件 ...
- Linux系统调用
在前面,我们接触到了很多函数能够实现系统相关的功能,比如解析命令行参数.控制进程以及映射内存等等.实际上,这些函数能够分为两大类: 库函数--这些函数就像普通函数一样,参数放置在寄存器或者栈里,运行时 ...
- linux命令连接远程服务器
ssh root@IP ***连接远程ip cd 路径 ***进入指定路径 ll ***查看当前文件 ll -a ...
- 【转】Nginx服务器详细配置含注释
#使用的用户和组 user www www; #指定工作衍生进程数(一般等于CPU的总核数或总核数的两倍) worker_processes 8; #指定错误日志存放的路径,错误日志的记录级别可为de ...
- net 调用https接口
public static void ProcessRequest() { //类似浏览器确认证书合法方法的绑定 ServicePointManager.ServerCertificateValida ...
- MvcPager 免费开源分页控件3.0版发布!
MvcPager 3.0版在原2.0版的基础上进行了较大的升级,对MvcPager脚本插件重写并进行了大量优化.修复了部分bug并新增了客户端Javascript API等功能,使用更方便,功能更强大 ...
- 探 寻 宝 藏--- DP
题目描述 传说HMH大沙漠中有一个M*N迷宫,里面藏有许多宝物.某天,Dr.Kong找到了迷宫的地图,他发现迷宫内处处有宝物,最珍贵的宝物就藏在右下角,迷宫的进出口在左上角.当然,迷宫中的通路不是平坦 ...