EN
Java - System.nanoTime() - what this methods really returns
11 points
System.nanoTime()
method returns the current value of the running Java Virtual Machine's high-resolution time source, in nanoseconds. The best application of this time could be measuring how much time took some operations.
xxxxxxxxxx
1
long t1 = System.nanoTime();
2
3
Thread.sleep(1000);
4
5
long t2 = System.nanoTime();
6
long dt = t2 - t1;
7
8
System.out.println("Sleeping time is " + dt + " ns.");
Output:
xxxxxxxxxx
1
Sleeping time is 1000143702 ns.