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
?>


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

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

清晰代码的执行效率。

posted @ 2014-08-25 16:50  TBHacker  阅读(494)  评论(0编辑  收藏  举报