How to calculate running time of a java program

Use System.nanoTime(), it returns the current value of the running Java Virtual Machine’s ( Please check JVM internal details ) high-resolution time source in nanoseconds.

Running time of a Java program
long startTime = System.nanoTime();

//... the program/code whose time being measured ...//

long endTime = System.nanoTime() 

long estimatedTime = endTime - startTime;

System.out.println(“Estimated Time: “ + estimatedTime);
Returns

It returns the current value of the running Java Virtual Machine’s high-resolution time source, in nanoseconds

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments