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 ...
随机推荐
- uva 11082
题意:知道矩阵的前i行之和,和前j列之和(任意i和j都可以).求这个矩阵.每个格子中的元素必须在1~20之间.矩阵大小上限20*20 #include<cstdio> #include&l ...
- Linux下SVN客户端安装及使用
转载自:http://www.linuxidc.com/Linux/2015-01/111748.htm 不想自己写了,这个写的挺全的,我就按这个步骤走的,呵呵 非常感谢作者 环境说明: 系统版本:C ...
- JS学习之函数内部属性和方法
知识点:arguments和this对象.caller属性.apply()和call()方法 arguments对象:函数内部对象,传入函数中所有参数的集合,类数组对象 属性:callee 指 ...
- [问题]数据库MySQL和Navicat的乱码问题
计算机中存储字符需要使用编码集,早期有ASCII集,但是随着技术的发展,ASCII集不能满足需求,出现了越来越多的字符,比如中文字符等.后来又发展出了Unicode.GB2312.utf8等字符集.字 ...
- 實際案例: 獲取臨時票証 (JsApi Ticket)
專案中選用大名鼎鼎的 Senparc 微信開發套件 獲取臨時票證處理常式的程式碼 (GetgVXinInfo.ashx) using Senparc.Weixin; using Senparc.Wei ...
- Cordova系列(一)
1.安装 这里推荐用npm安装cordova,至于npm的安装,网上有很多的.打开命令行,输入 npm install -g cordova 这里就安装了好了最新版的cordova,虽然绝大多数会成功 ...
- ReportViewer 不预览,直接导出 PDF文件
作为笔记记着,以免以后再到处找资料 1. 在不预览的情况下导出文件 先看一个方法说明,想知道ReportViewer支持导出哪些文件类型,在Render方法说明中就有描述 // // Summary: ...
- Docker-3:Data Volume
Sometimes, applications need to share access to data or persist data after a container is deleted. ...
- base64格式的图片如何上传到oss
---恢复内容开始--- 对于base64图片的上传这个东西,一直是一个问题尤其是上传到oss.我们这次开发由于需要修剪图片,使用了h5的很多新特性. h5修剪图片,使用了我们的canvas.这个步骤 ...
- Python 第五天 装饰器
装饰器 装饰器是函数,只不过该函数可以具有特殊的含义,装饰器用来装饰函数或类,使用装饰器可以在函数执行前和执行后添加相应操作. def wrapper(func): def result(): pri ...