You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
892 B
Java

/*************************************************************************
* Compilation: javac Stopwatch.java
*
*
*************************************************************************/
/**
* The Stopwatch data type is for measuring
* the time that elapses between the start and end of a
* programming task (wall-clock time).
*
* See {@link StopwatchCPU} for a version that measures CPU time.
*
* @author Robert Sedgewick
* @author Kevin Wayne
*/
public class Stopwatch {
private final long start;
/**
* Initialize a stopwatch object.
*/
public Stopwatch() {
start = System.currentTimeMillis();
}
/**
* Returns the elapsed time (in seconds) since this object was created.
*/
public double elapsedTime() {
long now = System.currentTimeMillis();
return (now - start) / 1000.0;
}
}