php计算函数执行时间的方法
本文实例讲述了php计算函数执行时间的方法。分享给大家供大家参考。具体如下:
我们可以通过在程序的前后分别记录开始和结束时间,两个时间差就是程序的执行时间。
<?php $long_str="thisisatesttoseehowmuchtimemd5functiontakestoexecuteoverthisstring"; //starttimingfromhere $start=microtime(true); //functiontotest $md5=md5($long_str); $elapsed=microtime(true)-$start; echo"Thattook$elapsedseconds.\n"; ?>
运行结果如下:
Thattook7.1525573730469E-6seconds.
php计算函数执行时间的方法及获得微妙的方法
//获得微妙方法
functiongetMillisecond()
{
list($s1,$s2)=explode('',microtime());
return(float)sprintf('%.0f',(floatval($s1)+floatval($s2))*1000);
}
原理:分别记录函数开始时间和结束时间,然后时间差就是函数执行的时间
<?php
$start_time=microtime(true);
for($i=1;$i<=1000;$i++){
echo$i.'<br>';
}
$end_time=microtime(true);
echo'循环执行时间为:'.($end_time-$start_time).'s';
?>
希望本文所述对大家的php程序设计有所帮助。
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短