public interface Timer
| Modifier and Type | Interface and Description |
|---|---|
static interface |
Timer.Timed
A timing sample that carries internal state about the Timer's start position.
|
| Modifier and Type | Method and Description |
|---|---|
long |
count()
The number of times
time(Duration) was called. |
default boolean |
isNoop()
Determines whether this timer is a NOOP timer.
|
void |
record(long amount,
java.util.concurrent.TimeUnit unit)
Records a custom amount in the given time unit.
|
Timer.Timed |
start()
Starts the timer and returns a
Timer.Timed instance. |
default void |
time(java.time.Duration duration)
The duration to record
|
void |
time(java.lang.Runnable runnable)
Executes and measures the given
Runnable instance. |
<T> T |
time(java.util.function.Supplier<T> supplier)
Gets the result from the given
Supplier and measures its execution time. |
<T> T |
timeCallable(java.util.concurrent.Callable<T> callable)
Executes and measures the given
Callable and returns its result. |
java.time.Duration |
totalDuration()
The total duration that was recorded.
|
default java.util.concurrent.TimeUnit |
unit()
The
TimeUnit of the timer. |
static final Timer NOOP
long count()
time(Duration) was called.time(Duration) was called.java.time.Duration totalDuration()
Timer.Timed start()
Timer.Timed instance. Call Timer.Timed.stop() to complete
the timing.Timer.Timed instance with the start time recorded.default java.util.concurrent.TimeUnit unit()
TimeUnit of the timer.TimeUnit of the timer.void record(long amount,
java.util.concurrent.TimeUnit unit)
amount - The amount to recordunit - The time unit of the amountdefault void time(java.time.Duration duration)
duration - The duration to recordvoid time(java.lang.Runnable runnable)
Runnable instance.runnable - The Runnable to execute and measure.<T> T timeCallable(java.util.concurrent.Callable<T> callable)
throws java.lang.Exception
Callable and returns its result.T - The type of the Callablecallable - The Callable to execute and measure.Callable.java.lang.Exception - In case the Callable fails.<T> T time(java.util.function.Supplier<T> supplier)
Supplier and measures its execution time.T - The type of the Supplier.supplier - The Supplier to execute and measure.Supplier.default boolean isNoop()