Skip to content

Instantly share code, notes, and snippets.

@tankala
Created April 21, 2018 09:48
Show Gist options
  • Save tankala/1838d038412c65598376b729a16c3586 to your computer and use it in GitHub Desktop.
Save tankala/1838d038412c65598376b729a16c3586 to your computer and use it in GitHub Desktop.
Execution Time Measurement Example in Java
public class ExecutionTimeMeasurementExample {
public static void main(String[] args) throws InterruptedException {
long startTime = System.currentTimeMillis();
sleepFunction(1000);
sleepFunction(1000);
long endTime = System.currentTimeMillis();
System.out.println("Program took " + (endTime - startTime) + " ms to complete");
}
private static void sleepFunction(int milliSecondsToSleep) throws InterruptedException {
long startTime = System.currentTimeMillis();
Thread.sleep(milliSecondsToSleep);
long endTime = System.currentTimeMillis();
System.out.println("My job done in " + (endTime - startTime) + " ms");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment