dongli8862 2013-06-28 06:26
浏览 48
已采纳

PHP执行时间测量精度

So I measure execution time like this:

$time = -microtime(true);
...
$time += microtime(true);

PHP version is 5.3.26RC1 x86 running on Win Server 2008 x64 machine. "Precision" ini parameter equals 16. However, each time the execution time is below 0.001, it just returns zero (obviously, the script can't be executed instantly!). What's even more strange, my test machine (standard php.ini-development) returns nonzero values even if there is no code between these two statements... What could be wrong?

Upd: Simple test:

<?php
ini_set('precision',16);
echo php_uname() . PHP_EOL;
echo phpversion() . PHP_EOL;
echo ini_get('precision').PHP_EOL;

$time = -microtime(true);
$time += microtime(true);
echo number_format($time, 10) .PHP_EOL;
?>

Test machine output:

Windows NT XXX 6.1 build 7601 (Windows 7 Ultimate Edition Service Pack 1) i586
5.4.12
16
0.0000028610

Production machine output:

Windows NT XXX 6.1 build 7601 (Windows Server 2008 R2 Standard Edition Service Pack 1) i586
5.3.26RC1
16
0.0000000000
  • 写回答

1条回答 默认 最新

  • dongya4089 2013-06-28 06:31
    关注

    Your platform, Windows, can not discriminate between such small times, with the standard time calls.

    A comment from the PHP source code:

    "on windows, time_sleep_until has millisecond accuracy while microtime() is accurate to 10th of a second."

    (In ext/standard/tests/misc/time_sleep_until_basic.phpt.)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog