我已经使用microtime()来检查代码的执行时间。 但似乎很奇怪,像跟踪的时间不正确。PHP microtime()是否正确?
在我的test.php的所以,我有这样的代码如下:
$debug = true;
$start = microtime(true);
$newline = "<br/>";
...
if ($debug) {
$time_elapsed_secs = microtime(true) - $start;
$start = microtime(true);
echo 'Step 1 Done: ' . $time_elapsed_secs . $newline; }
...
if ($debug) {
$time_elapsed_secs = microtime(true) - $start;
$start = microtime(true);
echo 'Step 2 Done: ' . $time_elapsed_secs . $newline; }
后来,当我打开浏览器的URL,它在不到1秒, 反应,但它显示了像 一些奇怪的值步骤1完成:0.0026565 步骤2完成:9.8646454
这是怎么发生的? 我做错了什么吗?
“完成第1步:0.0026565” 的意思,它采取0.0026565秒得到这一点。 “第2步完成:9.8646454”意味着它花费了9.8646454秒才能到达该点。 – samlev