kotlin icon indicating copy to clipboard operation
kotlin copied to clipboard

Used System.nanoTime() for measuring elapsed time

Open hafarooki opened this issue 6 years ago • 0 comments

System.currentTimeMillis() is less accurate for measuring elapsed time, as System.nanoTime() is guaranteed to have at least as good accuracy.

According to the Oracle docs:

while the unit of time of the return value is a millisecond, the granularity of the value depends on the underlying operating system and may be larger. For example, many operating systems measure time in units of tens of milliseconds.

Whereas, 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 origin time (perhaps in the future, so values may be negative).

hafarooki avatar Nov 07 '18 13:11 hafarooki