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
| Modifier and Type | Field and Description |
|---|---|
| private long | |
| pack-priv boolean | running
Flags if this object is started or stopped. |
| private long | startTime
The last time this object made the transition from stopped to running state, as reported by System.nanoTime(). |
| private long | total
The accumulated running time of this object since it was last zeroed. |
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public long | Returns: the accumulated nanoseconds this object has spent running since it was last started.Retrieves the accumulated nanoseconds this object has spent running since it was last started. |
| public String | Returns: prefix + " in " + elapsedTime() + " ns."The string to use as a prefix prefix)Retrieves prefix + " in " + elapsedTime() + " ns." |
| public long | Returns: the accumulated milliseconds this object has spent running since it was last started.Retrieves the accumulated milliseconds this object has spent running since it was last started. |
| public String | Returns: prefix + " in " + elapsedTime() + " ms."The string to use as a prefix prefix)Retrieves prefix + " in " + elapsedTime() + " ms." |
| public long | Returns: the accumulated nanoseconds this object has spent running since it was last zeroed.Retrieves the accumulated nanoseconds this object has spent running since it was last zeroed. |
| public String | Returns: prefix + " in " + elapsedNanos() + " ns."The string to use as a prefix prefix)Retrieves prefix + " in " + elapsedNanos() + " ns." |
| public long | Returns: the accumulated milliseconds this object has spent running since it was last zeroed.Retrieves the accumulated milliseconds this object has spent running since it was last zeroed. |
| public String | Returns: prefix + " in " + elapsedTime() + " ms."The string to use as a prefix prefix)Retrieves prefix + " in " + elapsedTime() + " ms." |
| public void | |
| public void | |
| public void | |
| public String | Returns: the state of this object, as a StringOverrides java. Retrieves the internal state of this object, as a String. |
| public void |
| lastStart | back to summary |
|---|---|
| private long lastStart | |
| running | back to summary |
|---|---|
| pack-priv boolean running Flags if this object is started or stopped. | |
| startTime | back to summary |
|---|---|
| private long startTime The last time this object made the transition from stopped to running state, as reported by System.nanoTime(). | |
| total | back to summary |
|---|---|
| private long total The accumulated running time of this object since it was last zeroed. | |
| StopWatch | back to summary |
|---|---|
| public StopWatch() Creates, zeros, and starts a new StopWatch | |
| StopWatch | back to summary |
|---|---|
| public StopWatch(boolean start) Creates, zeros, and starts a new StopWatch
| |
| currentElapsedNanos | back to summary |
|---|---|
| public long currentElapsedNanos() Retrieves the accumulated nanoseconds this object has spent running since it was last started.
| |
| currentElapsedNanosToMessage | back to summary |
|---|---|
| public String currentElapsedNanosToMessage(String prefix) Retrieves prefix + " in " + elapsedTime() + " ns." | |
| currentElapsedTime | back to summary |
|---|---|
| public long currentElapsedTime() Retrieves the accumulated milliseconds this object has spent running since it was last started.
| |
| currentElapsedTimeToMessage | back to summary |
|---|---|
| public String currentElapsedTimeToMessage(String prefix) Retrieves prefix + " in " + elapsedTime() + " ms." | |
| elapsedNanos | back to summary |
|---|---|
| public long elapsedNanos() Retrieves the accumulated nanoseconds this object has spent running since it was last zeroed.
| |
| elapsedNanosToMessage | back to summary |
|---|---|
| public String elapsedNanosToMessage(String prefix) Retrieves prefix + " in " + elapsedNanos() + " ns." | |
| elapsedTime | back to summary |
|---|---|
| public long elapsedTime() Retrieves the accumulated milliseconds this object has spent running since it was last zeroed.
| |
| elapsedTimeToMessage | back to summary |
|---|---|
| public String elapsedTimeToMessage(String prefix) Retrieves prefix + " in " + elapsedTime() + " ms." | |
| mark | back to summary |
|---|---|
| public void mark() | |
| start | back to summary |
|---|---|
| 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 the | |
| stop | back to summary |
|---|---|
| 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 the
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Retrieves the internal state of this object, as a String. The retrieved value is: super.toString() + "[running=" + running + ", startTime=" + startTime + ", total=" + total + "]";
| |
| zero | back to summary |
|---|---|
| public void zero() Zeros accumulated running time and restarts this object. | |