@NotThreadSafe public class StopWatch extends Object implements IStoppable
System.nanoTime().| Modifier | Constructor and Description |
|---|---|
protected |
StopWatch(boolean bStart)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
static StopWatch |
createdStarted() |
static StopWatch |
createdStopped() |
protected static long |
getCurrentNanoTime() |
Duration |
getDuration() |
Duration |
getLapDuration()
Create an intermediate time (lap time).
|
long |
getMillis() |
long |
getNanos() |
long |
getSeconds()
Deprecated.
|
boolean |
isStarted() |
boolean |
isStopped() |
EChange |
reset()
Reset all saved durations, in case this stop watch is to be used in a loop.
|
void |
restart()
Stops, resets and starts the stop watch.
|
static Duration |
runMeasured(Runnable aRunnable)
Run the passed runnable and measure the time.
|
EChange |
start()
Start the stop watch.
|
EChange |
stop()
Stop the stop watch.
|
Duration |
stopAndGetDuration()
Stop the stop watch and get the duration since the start.
|
long |
stopAndGetMillis()
Stop the stop watch and get the elapsed milliseconds since the start.
|
long |
stopAndGetNanos()
Deprecated.
|
long |
stopAndGetSeconds()
Deprecated.
|
String |
toString() |
protected StopWatch(boolean bStart)
bStart - if true the stop watch is directly started!@Nonnull public EChange reset()
EChange.protected static final long getCurrentNanoTime()
@Nonnull public EChange stop()
stop in interface IStoppableEChange.CHANGED if the stop watch was previously running
and is now stopped, and EChange.UNCHANGED if the stop watch
was already stopped.public void restart()
public boolean isStarted()
true if the stop watch is currently started (running),
false otherwise.public boolean isStopped()
true if the stop watch is currently stopped (not
running), false otherwise.@Nonnegative public long getNanos()
@Nonnegative public long getMillis()
@Nonnegative @Deprecated public long getSeconds()
@Nonnegative @Deprecated public long stopAndGetNanos()
@Nonnegative public long stopAndGetMillis()
@Nonnegative @Deprecated public long stopAndGetSeconds()
@Nonnull public Duration stopAndGetDuration()
@Nonnull public Duration getLapDuration()
@Nonnull @ReturnsMutableCopy public static StopWatch createdStarted()
StopWatch object that is started. Never
null.@Nonnull @ReturnsMutableCopy public static StopWatch createdStopped()
StopWatch object that is NOT started. Never
null.@Nonnull public static Duration runMeasured(@Nonnull Runnable aRunnable)
aRunnable - The runnable to be executed. May not be null.null.Copyright © 2014–2022 Philip Helger. All rights reserved.