Core API
How do I calculate process execution time in higher resolution?
This example demonstrates how to use the System.nanoTime() method to calculate processing execution time in higher resolution. The processing time calculated in nanoseconds resolution. package org.kodejava.lang; public class NanoSecondsTimerResolution { public static void main(String[] args) { // Get process execution start time in nanoseconds. long start = System.nanoTime(); System.out.println("Process start… " + start); try { […]
Artikel oleh Wayan · Sumber: Kode Java ↗
Terjemahan artikel ini belum tersedia. Isi asli ditampilkan.
This example demonstrates how to use the System.nanoTime() method to calculate processing execution time in higher resolution. The processing time calculated in nanoseconds resolution.
package org.kodejava.lang;
public class NanoSecondsTimerResolution {
public static void main(String[] args) {
// Get process execution start time in nanoseconds.
long start = System.nanoTime();
System.out.println("Process start... " + start);
try {
Thread.sleep(5000); // Simulate a long process.
} catch (InterruptedException e) {
e.printStackTrace();
}
// Get process execution finish time in nanoseconds.
long finish = System.nanoTime();
System.out.println("Process finish... " + finish);
// Calculate the process execution time.
long execTime = finish - start;
System.out.println("Processing time = " + execTime + "(ns)");
}
}
