java.lang.Object
org.hsqldb.lib.StopWatch
Provides the programatic analog of a physical stop watch.
The watch can be started, stopped and zeroed and can be queried for elapsed running time. The watch accumulates elapsed time over starts and stops such that only the time actually spent running is recorded. If the watch is zeroed, then the accumulated time is discarded and the watch starts again with zero accumulated time.
Nanosecond support added by fredt@users
- Since:
- 1.7.2
- Author:
- Campbell Burnet (campbell-burnet@users dot sourceforge.net)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlong
Retrieves the accumulated nanoseconds this object has spent running since it was last started.currentElapsedNanosToMessage
(String prefix) Retrieves prefix + " in " + elapsedTime() + " ns."long
Retrieves the accumulated milliseconds this object has spent running since it was last started.currentElapsedTimeToMessage
(String prefix) Retrieves prefix + " in " + elapsedTime() + " ms."long
Retrieves the accumulated nanoseconds this object has spent running since it was last zeroed.elapsedNanosToMessage
(String prefix) Retrieves prefix + " in " + elapsedNanos() + " ns."long
Retrieves the accumulated milliseconds this object has spent running since it was last zeroed.elapsedTimeToMessage
(String prefix) Retrieves prefix + " in " + elapsedTime() + " ms."void
mark()
void
start()
Ensures that this object is in the running state.void
stop()
Ensures that this object is in the stopped state.toString()
Retrieves the internal state of this object, as a String.void
zero()
Zeros accumulated running time and restarts this object.
-
Constructor Details
-
StopWatch
public StopWatch()Creates, zeros, and starts a new StopWatch -
StopWatch
public StopWatch(boolean start) Creates, zeros, and starts a new StopWatch- Parameters:
start
- boolean
-
-
Method Details
-
elapsedTime
public long elapsedTime()Retrieves the accumulated milliseconds this object has spent running since it was last zeroed.- Returns:
- the accumulated milliseconds this object has spent running since it was last zeroed.
-
elapsedNanos
public long elapsedNanos()Retrieves the accumulated nanoseconds this object has spent running since it was last zeroed.- Returns:
- the accumulated nanoseconds this object has spent running since it was last zeroed.
-
currentElapsedTime
public long currentElapsedTime()Retrieves the accumulated milliseconds this object has spent running since it was last started.- Returns:
- the accumulated milliseconds this object has spent running since it was last started.
-
currentElapsedNanos
public long currentElapsedNanos()Retrieves the accumulated nanoseconds this object has spent running since it was last started.- Returns:
- the accumulated nanoseconds this object has spent running since it was last started.
-
zero
public void zero()Zeros accumulated running time and restarts this object. -
start
public void start()Ensures that this object is in the running state. If this object is not running, then the call has the effect of setting thestartTime
attribute to the current value of System.nanoTime() and setting therunning
attribute totrue
. -
stop
public void stop()Ensures that this object is in the stopped state. If this object is in the running state, then this has the effect of adding to thetotal
attribute the elapsed time since the last transition from stopped to running state and sets therunning
attribute to false. If this object is not in the running state, this call has no effect. -
mark
public void mark() -
elapsedTimeToMessage
Retrieves prefix + " in " + elapsedTime() + " ms."- Parameters:
prefix
- The string to use as a prefix- Returns:
- prefix + " in " + elapsedTime() + " ms."
-
elapsedNanosToMessage
Retrieves prefix + " in " + elapsedNanos() + " ns."- Parameters:
prefix
- The string to use as a prefix- Returns:
- prefix + " in " + elapsedNanos() + " ns."
-
currentElapsedTimeToMessage
Retrieves prefix + " in " + elapsedTime() + " ms."- Parameters:
prefix
- The string to use as a prefix- Returns:
- prefix + " in " + elapsedTime() + " ms."
-
currentElapsedNanosToMessage
Retrieves prefix + " in " + elapsedTime() + " ns."- Parameters:
prefix
- The string to use as a prefix- Returns:
- prefix + " in " + elapsedTime() + " ns."
-
toString
Retrieves the internal state of this object, as a String. The retrieved value is:super.toString() + "[running=" + running + ", startTime=" + startTime + ", total=" + total + "]";
-