Package groovy.time
Record Class Timed<T>
java.lang.Object
java.lang.Record
groovy.time.Timed<T>
- Type Parameters:
T- the type of the timed result- Record Components:
result- the value returned by the timed codenanos- the elapsed time in nanoseconds, as measured bySystem.nanoTime()
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
- Since:
- 6.0.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.Returns the elapsed time as aDuration.longReturns the elapsed time in whole milliseconds, truncated toward zero.final inthashCode()Returns a hash code value for this object.longnanos()Returns the value of thenanosrecord component.result()Returns the value of theresultrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
Method Details
-
getDuration
Returns the elapsed time as aDuration. Exposed to Groovy as the read-onlydurationproperty.- Returns:
- the elapsed time as a
Duration - Since:
- 6.0.0
-
getMillis
public long getMillis()Returns the elapsed time in whole milliseconds, truncated toward zero. Exposed to Groovy as the read-onlymillisproperty.- Returns:
- the elapsed time in milliseconds
- Since:
- 6.0.0
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
result
Returns the value of theresultrecord component.- Returns:
- the value of the
resultrecord component
-
nanos
public long nanos()Returns the value of thenanosrecord component.- Returns:
- the value of the
nanosrecord component
-