Stopwatch.java


Below is the syntax highlighted version of Stopwatch.java from §4.2 Sorting and Searching.


/*************************************************************************
 *  Compilation:  javac Stopwatch.java
 *
 *************************************************************************/

public class Stopwatch { 

   // time that this object was created
   private final long start;

   public Stopwatch() {
       start = System.currentTimeMillis();
   } 

   // return time (in seconds) since this object was created
   public double elapsedTime() {
       return (System.currentTimeMillis() - start) / 1000.0;
   } 

} 


Copyright © 2007, Robert Sedgewick and Kevin Wayne.
Last updated: Tue Sep 29 16:17:41 EDT 2009.