Skip to content

Instantly share code, notes, and snippets.

@wilsonmar
Created March 16, 2015 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilsonmar/760d6bfad69090a49dd2 to your computer and use it in GitHub Desktop.
Save wilsonmar/760d6bfad69090a49dd2 to your computer and use it in GitHub Desktop.
Java execution timer
// 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");
}
}
@wilsonmar
Copy link
Author

new

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment