java nanotime单位_java – System.nanoTime()的精度与精度

System.nanoTime()的文件说如下(强调我的)。

This method can only be used to measure elapsed time and is not related to any other notion of system or wall-clock time. The value returned represents nanoseconds since some fixed but arbitrary time (perhaps in the future, so values may be negative). This method provides nanosecond precision, but not necessarily nanosecond accuracy. No guarantees are made about how frequently values change.

正如我所看到的,这可以用两种不同的方式解释:

>上面粗体的句子是指个人的返回值。那么,精确度和准确度就是从数字上来理解的。也就是说,精度是指有效数字的数量 – 截断的位置,精度是否是正确的数字(如在这里的最高答案中所述

What is the difference between ‘precision’ and ‘accuracy’?)

>以上粗体的句子是指方法本身的能力。然后,精确度和准确性将被理解为飞镖类比所示

(http://en.wikipedia.org/wiki/Precision_vs._accuracy#Accuracy_versus_precision:_the_target_analogy)。

因此,精度低,精度高=>错误的值以高精度反复击打:想象物理时间依然存在,nanoTime()的连续调用返回相同的数值,但是从参考时间以后的实际经过时间偏离了一些常数偏移量。

哪一个解释是正确的?我的观点是,解释2将意味着使用nanoTime()(通过减去两个返回值)的时间差的度量对于纳秒是正确的(因为测量中的恒定误差/偏移将被消除),而解释1将会不能保证测量之间的一致性,因此不一定意味着高精度的时差测量。

更新4/15/13:System.nanoTime()的Java 7文档已更新,以解决与以前的措辞可能的混淆。

Returns the current value of the running Java Virtual Machine’s high-resolution time source, in nanoseconds.

This method can only be used to measure elapsed time and is not related to any other notion of system or wall-clock time. The value returned represents nanoseconds since some fixed but arbitrary origin time (perhaps in the future, so values may be negative). The same origin is used by all invocations of this method in an instance of a Java virtual machine; other virtual machine instances are likely to use a different origin.

This method provides nanosecond precision, but not necessarily nanosecond resolution (that is, how frequently the value changes) – no guarantees are made except that the resolution is at least as good as that of 07004.

Differences in successive calls that span greater than approximately 292 years (263 nanoseconds) will not correctly compute elapsed time due to numerical overflow.

The values returned by this method become meaningful only when the difference between two such values, obtained within the same instance of a Java virtual machine, is computed.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值