页面加载时间
问题描述:
第一种方法页面加载时间
$start = microtime(true);
// code
$end = microtime(true);
echo 'This page loaded in '.round($end - $start, 4).' sec';
方法二
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$start = $time;
// code
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$finish = $time;
$total_time = round(($finish - $start), 4);
echo 'This page loaded in '.$total_time.' sec';
它们之间有什么区别,哪个更好?你还有其他建议吗?
答
的主要区别在于,第一实施例将不会PHP4工作,而第二个将(见手册的changelog一部分)。如果你的代码不能在PHP4上运行(我认为没有新的代码),那么你可以使用第一个代码,因为它的代码更少,所以速度稍快。
感谢您的答复@ complex857。 7分钟后我会接受你的回答:) – Ben 2012-07-30 07:02:59