|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
Timer.java | - | 50% | 75% | 60% |
|
1 |
package junit.extensions.abbot;
|
|
2 |
|
|
3 |
|
|
4 |
/**
|
|
5 |
Time and performance measurement utilities.
|
|
6 |
|
|
7 |
@author twall
|
|
8 |
*/
|
|
9 |
|
|
10 |
public class Timer { |
|
11 |
/** Time base for elapsed time calculations. */
|
|
12 |
private long start; |
|
13 |
|
|
14 |
/** Basic constructor which sets the timer base to the current time. */
|
|
15 | 919 |
public Timer() {
|
16 | 919 |
reset(); |
17 |
} |
|
18 |
|
|
19 |
/** Return the number of milliseconds elapsed since the last timer
|
|
20 |
reset. */
|
|
21 | 5139865 |
public long elapsed() { |
22 | 5139865 |
return System.currentTimeMillis() - start;
|
23 |
} |
|
24 |
|
|
25 |
/** Return the length of time elapsed to run the given runnable. */
|
|
26 | 0 |
public long elapsed(Runnable action) { |
27 | 0 |
long start = System.currentTimeMillis();
|
28 | 0 |
action.run(); |
29 | 0 |
return System.currentTimeMillis() - start;
|
30 |
} |
|
31 |
|
|
32 |
/** Set the start time to the current time. */
|
|
33 | 935 |
public void reset() { |
34 | 935 |
start = System.currentTimeMillis(); |
35 |
} |
|
36 |
} |
|
37 |
|
|