All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
asp.net2.0中水晶报表的应用实例
技巧:ASP.NET,2.0防止同一用户同时登陆_.net资料_编程技术
ASP.NET服务器控件之控件状态_[Asp.Net教程]
配置Apache2+PHP5+MYSQL5_[PHP教程]
ASP.NET应用程序_[Asp.Net教程]
sql语句_mssql学习_编程技术
你必须知道的.NET之特性和属性_.net资料_编程技术
数据库设计正规化的五大范式_[SQL Server教程]
XP上安装SqlServer2000_[SQL Server教程]
新手入门:IIS6环境下的PHP最佳配置方法_php资料_编程技术
Reading number is top 10 pictures
So beauty, will let you spray blood8
Steal to eat bacon bird
小学生作文又现神作,你不得不佩服
The world's ten biggest attractions of inventory super the moon
From China fortress sora aoi1
Hunan road lawenforcement vehicle pursue overload car caused the car turn and man is died
So beauty, will let you spray blood6
In 2013 hercules Arnold classic1
Absolutely shocked. National geographic 50 animal photographys10
Absolutely shocked. National geographic 50 animal photographys5
Download software ranking
Boxer's Top ten classic battle8
Unix video tutorial12
Unix video tutorial8
Photoshop 8.0图象编辑软件
Unix video tutorial17
The king of fighters 97(Mobile phone games-apk)
JSP+Ajax Web development typical examples
Tram sex maniac 2 (H) rar bag5
WebService在.NET中的实战应用教学视频 → 第2集
Love the forty days
aaa published in(发表于) 2013/12/21 22:24:55 Edit(编辑)
php中关于处理字符串时效率的讨论_php资料_编程技术

php中关于处理字符串时效率的讨论_php资料_编程技术

php中关于处理字符串时效率的讨论_php资料_编程技术-你的首页-uuhomepage.com

  有一堆类似以下变量$abc的字符串,末尾都多出来了一个,(逗号),我想去掉末尾的逗号,为了验证不同的处理方法的执行时间,以下是我写的一个对比程序进行试验:

  程序一,利用substr

function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}

$time_start = getmicrotime();

$abc="重庆,万州,涪陵,渝中,大渡口,江北,沙坪坝,九龙坡,南岸,北碚,万盛,双挢,渝北,巴南,黔江,长寿,綦江,潼南,铜梁,大足,荣昌,壁山,梁平,城口,丰都,垫江,武隆,忠县,开县,云阳,奉节,巫山,巫溪,石柱,";

$l=strlen($abc);
$abc=substr($abc,0,$l-1);
echo $abc."
";
$time_end = getmicrotime();
echo ($time_end-$time_start)*1000;
?>

  程序二,利用正则表达式

function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}

$time_start = getmicrotime();

$abc="重庆,万州,涪陵,渝中,大渡口,江北,沙坪坝,九龙坡,南岸,北碚,万盛,双挢,渝北,巴南,黔江,长寿,綦江,潼南,铜梁,大足,荣昌,壁山,梁平,城口,丰都,垫江,武隆,忠县,开县,云阳,奉节,巫山,巫溪,石柱,";

$abc=str_replace(",$","",$abc);
echo $abc."
";
$time_end = getmicrotime();
echo ($time_end-$time_start)*1000;
?>

  结果程序一的执行平均时间为0.045,程序二的执行平均时间为0.085。不进行任何处理的平均执行时间为0.041

  可见利用第一种方法处理效率要高出尽50%

  由此,我们在做程序的过程中,尤其是在要求高效的程序中,我们应该对不同的方法进行一下对比,找出最优化的处理方法。




添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.