I tested some algorithms in which I was surrounded by a nanosecond timer, when I accidentally forgot to delete the timer, I found out that this code:
a = System.nanoTime();
System.out.println(System.nanoTime() - a);
always prints 4400 nano seconds on my system. This will be 4.4 microseconds, while this code is:
a = System.currentTimeMillis();
for (int i = 0; i < 1000; i++)
System.nanoTime();
System.out.println(System.currentTimeMillis() - a);
Fingerprints 0
source
share