Created
March 16, 2015 15:51
-
-
Save wilsonmar/760d6bfad69090a49dd2 to your computer and use it in GitHub Desktop.
Java execution timer
This file contains 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
// From http://www.rgagnon.com/javadetails/java-0132.html | |
// quoted in http://stackoverflow.com/questions/5471700/is-there-a-command-in-java-to-measure-the-execution-time | |
public class ExecutionTimer { | |
private long start; | |
private long end; | |
public ExecutionTimer() { | |
reset(); | |
start = System.currentTimeMillis(); | |
} | |
public void end() { | |
end = System.currentTimeMillis(); | |
} | |
public long duration(){ | |
return (end-start); | |
} | |
public void reset() { | |
start = 0; | |
end = 0; | |
} | |
public static void main(String s[]) { | |
// simple example | |
ExecutionTimer t = new ExecutionTimer(); | |
for (int i=0; i < 80; i++){ System.out.print(".");} | |
t.end(); | |
System.out.println("\n" + t.duration() + " ms"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
new