Home > DeveloperSection > Forums > How do I time a method's execution in Java?
naomi burke
naomi burke

Total Post:28

Posted on    August-07-2015 5:32 AM

 Java Java 

 1 Reply(s)
 958  View(s)
Rate this:
How do I get a method's execution time? Is there a Timer utility class for things like timing how long a task takes, etc?

Most of the searches on Google return results for timers that schedule threads and tasks, which is not what I want.

Mayank Tripathi
Mayank Tripathi

Total Post:397

Posted on    August-07-2015 6:20 AM

There is always the old-fashioned way:

long startTime = System.nanoTime();
long endTime = System.nanoTime();
long duration = (endTime - startTime); 

Don't want to miss updates? Please click the below button!

Follow MindStick