php计算函数执行时间的技巧
发布时间:2022-08-04 16:44:54 所属栏目:PHP教程 来源:互联网
导读:这篇文章主要介绍了php计算函数执行时间的方法,以md5函数加密运行时间为例分析了php计算函数运行时间的技巧,需要的朋友可以参考下. ?php $long_str = this is a test to see how much time md5 function takes to execute over this string; // start timing
这篇文章主要介绍了php计算函数执行时间的方法,以md5函数加密运行时间为例分析了php计算函数运行时间的技巧,需要的朋友可以参考下. <?php $long_str = "this is a test to see how much time md5 function takes to execute over this string"; // start timing from here $start = microtime(true); 运行结果如下: That took 7.1525573730469E-6 seconds. php 计算函数执行时间的方法及获得微妙的方法 // 获得微妙方法 function getMillisecond() { 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'; ?> (编辑:应用网_丽江站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |