Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is System.currentTimeMillis() the best measure of time performance in Java?

Is System.currentTimeMillis() the best measure of time performance in Java? Are there any gotcha's when using this to compare the time before action is taken to the time after the action is taken? Is there a better alternative?

like image 636
dreadwail Avatar asked Jul 02 '09 09:07

dreadwail


People also ask

Is system currentTimeMillis accurate?

System. currentTimeMillis() will give you the most accurate possible elapsed time in milliseconds since the epoch, but System. nanoTime() gives you a nanosecond-precise time, relative to some arbitrary point. Returns the current value of the most precise available system timer, in nanoseconds.

How Fast Is system currentTimeMillis?

System. currentTimeMillis() takes about 29 nanoseconds per call while System.

What is the use of system currentTimeMillis ()?

currentTimeMillis() method returns the current time in milliseconds. 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.

How long does system nanoTime take?

public static long nanoTime() // Returns the current value of the running JVM's high-resolution // time source, in nanoseconds. Pros: Highly precise. The time returned is around 1/1000000th of a second.


1 Answers

I hope not - it's what I use when i don't use nanoTime().

like image 94
David Johnstone Avatar answered Oct 15 '22 10:10

David Johnstone