Package edu.odu.cs.cs350
Class Stopwatch
java.lang.Object
edu.odu.cs.cs350.Stopwatch
A simple utility class for measuring elapsed execution time.
The Stopwatch records the starting time when start() is
called, and computes elapsed time on demand using elapsedSeconds()
or elapsedMilliseconds().
This class does not automatically stop; the stopwatch is considered to "stop" at the moment an elapsed time method is called. This makes it suitable for profiling individual operations or measuring the total runtime of a program segment.
-
Constructor Details
-
Stopwatch
public Stopwatch()
-
-
Method Details
-
start
public void start()Starts or restarts the stopwatch.This method captures the current time in nanoseconds and overwrites any previously stored start time.
-
elapsedSeconds
public double elapsedSeconds()Returns the elapsed time in seconds since the last call tostart().This method does not stop the stopwatch; it simply computes the elapsed difference between the current time and
startTime.- Returns:
- elapsed time in seconds as a double
-
elapsedMilliseconds
public long elapsedMilliseconds()Returns the elapsed time in milliseconds since the last call tostart().- Returns:
- elapsed time in milliseconds as a long
-