01: package junit.extensions.abbot;
02:
03: /**
04: Time and performance measurement utilities.
05:
06: @author twall
07: */
08:
09: public class Timer {
10: /** Time base for elapsed time calculations. */
11: private long start;
12:
13: /** Basic constructor which sets the timer base to the current time. */
14: public Timer() {
15: reset();
16: }
17:
18: /** Return the number of milliseconds elapsed since the last timer
19: reset. */
20: public long elapsed() {
21: return System.currentTimeMillis() - start;
22: }
23:
24: /** Return the length of time elapsed to run the given runnable. */
25: public long elapsed(Runnable action) {
26: long start = System.currentTimeMillis();
27: action.run();
28: return System.currentTimeMillis() - start;
29: }
30:
31: /** Set the start time to the current time. */
32: public void reset() {
33: start = System.currentTimeMillis();
34: }
35: }
|