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 asp.textbox后台赋值前端不能显示什么原因
  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误