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程序设计有所帮助。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下