/Users/lyon/j4p/src/collections/stringswitch/Timer.java
|
1 /*
2 * Timer.java
3 *
4 * Created on October 30, 2002
5 */
6
7 package collections.stringswitch;
8
9 import java.io.PrintStream;
10
11 /**
12 * @author Thomas Rowland
13 */
14 public class Timer {
15
16 private long base_time;
17 private long elapsed_time;
18 private static final long UNIT = 1000;
19
20 /** Creates a new instance of Timer */
21 public Timer() {
22 clear();
23 }
24
25 public void mark() {
26 base_time = System.currentTimeMillis();
27 }
28
29 public void clear() {
30 elapsed_time = 0;
31 }
32
33 public void record() {
34 elapsed_time += (System.currentTimeMillis() - base_time);
35 }
36
37 public float elapsed() {
38 return ((float) elapsed_time) / UNIT;
39 }
40
41 public void report(PrintStream ps) {
42 float elapsed_secs = elapsed();
43 ps.println("Time " + elapsed_secs + " sec");
44 }
45
46 public void report() {
47 report(System.out);
48 }
49
50 }
51