public record Timed
extends Record
An immutable holder for the outcome of a timed execution: the value produced
together with the elapsed time in nanoseconds. Instances are created by the
timed extension method rather than being constructed directly.
The elapsed time is measured with System.nanoTime, which is
monotonic and unaffected by wall-clock adjustments. Convenience views of the
duration are available via getDuration() and getMillis(),
which Groovy exposes as the duration and millis properties.
def t = System.timed { (1..1_000).sum() }
assert t.result == 500_500
assert t.nanos >= 0
assert t.duration instanceof java.time.Duration
T - the type of the timed resultresult - the value returned by the timed codenanos - the elapsed time in nanoseconds, as measured by System.nanoTime| Type Params | Return Type | Name and description |
|---|---|---|
|
public Duration |
getDuration()Returns the elapsed time as a Duration. |
|
public long |
getMillis()Returns the elapsed time in whole milliseconds, truncated toward zero. |
Returns the elapsed time as a Duration. Exposed to Groovy
as the read-only duration property.
Duration Returns the elapsed time in whole milliseconds, truncated toward zero.
Exposed to Groovy as the read-only millis property.