Created
April 21, 2018 09:48
-
-
Save tankala/1838d038412c65598376b729a16c3586 to your computer and use it in GitHub Desktop.
Execution Time Measurement Example in Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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