Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capturing the executing time between 2 statements Java?

I want to capture the time take to go from statement A to Statement B in a Java class. In between these statements there are many web service calls made. I wanted to know if there is some stop watch like functionality in java that i could use to capture the exact time?

Kaddy

like image 811
Kaddy Avatar asked Jul 06 '10 20:07

Kaddy


1 Answers

This will give you the number of nanoseconds between the two nanoTime() calls.

long start = System.nanoTime();
// Java statements
long diff = System.nanoTime() - start;

For more sophisticated approaches there are several duplicate questions that address Stopwatch classes:

  • Java performance timing library
  • Stopwatch class for Java
like image 108
Ben S Avatar answered Nov 17 '22 07:11

Ben S