kotlin
kotlin copied to clipboard
Used System.nanoTime() for measuring elapsed time
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).