microtime() 测试代码执行时间,提高编码效率

microtime() 测试代码执行时间,提高编码效率
<?php
$b_time = microtime(true);
$a = array("1","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2");
$count = 0;
foreach ($a as $key => $value) {
 foreach ($a as $key => $value) {
  foreach ($a as $key => $value) {
   $b = 1*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8;
   //$count++;
  }
 }
}
$e_time = microtime(true);
$taketime = $e_time-$b_time;
//echo $taketime;
echo $taketime;
//3.5078401565552
//0.68016886711121
//15.500303983688
?>
microtime() 测试代码执行时间,提高编码效率


它能精确到很细微的时间。不仅仅是秒。

在代码执行体首尾加上,可以检测执行的时间情况。

清晰代码的执行效率。


本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/3935322.html,如需转载请自行联系原作者


上一篇:javascript 手机移动端 微信 拍照 录音 录视频并阿里oss上传


下一篇:.NET WinForm中使用Timer定时更新ProgressBar的进度