Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: junit/extensions/abbot/Timer.java


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