Skip to content

Instantly share code, notes, and snippets.

@julianthome
Created September 18, 2016 12:48
Show Gist options
  • Save julianthome/41473cf2e2ad3bfa0eff7e0dd628bd8e to your computer and use it in GitHub Desktop.
Save julianthome/41473cf2e2ad3bfa0eff7e0dd628bd8e to your computer and use it in GitHub Desktop.
A simple stop watch implemented in Java
public class StopWatch {
long start;
long end;
long time;
long overallTime = 0;
public static StopWatch get() {
return new StopWatch();
}
private StopWatch() { start = 0; end = 0; time = 0; overallTime = 0;}
public void start() {
this.start = System.currentTimeMillis();
}
public long stop() {
this.end = System.currentTimeMillis();
if(this.end > this.start) {
this.time = this.end - this.start;
} else {
this.time = 0L;
}
this.end = 0; this.start = 0;
this.overallTime += time;
return time;
}
public long getTime() {
return this.time;
}
public long getOverallTime() {
return this.overallTime;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment