计算页面执行时间

          很多网站,论坛啊,底部都有页面加载执行完成所需要的时间,这点可以反映程序性能网速等。其实实现这个功能非常简单.

下面实例代码:

<?php
function microtime_float(){
  list($usec,$sec) = explode(" ", microtime());
  return ((float)$usec + (float)$sec);//$usec微秒,$sec秒数 两者单位均为秒
}

$time_start = microtime_float();
$time_start1=microtime(true);
usleep(100);//delay 100microseconds

$time_end = microtime_float();
$time_end1=microtime(true);
$time = $time_end - $time_start;

echo "Did nothing in $time seconds <br/>";
echo "<br/>精确点的:<br/>$time_end - $time_start=".($time_end - $time_start);
echo "<hr/>";
echo "不够精确的:<br/>$time_end1 - $time_start1=".($time_end1 - $time_start1);

?>

 

 

posted @ 2013-06-13 17:23  H&K  阅读(229)  评论(0编辑  收藏  举报