Java中的精确时间测量 [英] Precise time measurement in Java

查看:54
本文介绍了Java中的精确时间测量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java 提供了两种获取当前时间的方法:System.nanoTime()System.currentTimeMillis().第一个给出了以纳秒为单位的结果,但实际精度比这差很多(许多微秒).

Java gives access to two method to get the current time: System.nanoTime() and System.currentTimeMillis(). The first one gives a result in nanoseconds, but the actual accuracy is much worse than that (many microseconds).

JVM 是否已经为每台特定机器提供了可能的最佳价值?否则,是否有一些 Java 库可以提供更精细的测量,可能是通过绑定到特定系统?

Is the JVM already providing the best possible value for each particular machine? Otherwise, is there some Java library that can give finer measurement, possibly by being tied to a particular system?

推荐答案

获得超精确时间测量的问题在于某些处理器不能/不提供如此微小的增量.

The problem with getting super precise time measurements is that some processors can't/don't provide such tiny increments.

据我所知,System.currentTimeMillis()System.nanoTime() 是您能找到的最佳度量.

As far as I know, System.currentTimeMillis() and System.nanoTime() is the best measurement you will be able to find.

请注意,两者都返回一个 long 值.

Note that both return a long value.

这篇关于Java中的精确时间测量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆