public class System
extends Object
GDK enhancements for System.
| Modifiers | Name | Description |
|---|---|---|
static interface |
System.Logger |
GDK enhancements for Logger. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static long |
currentTimeSeconds(System self)Get the current time in seconds |
<T> |
public static Timed<T> |
timed(System self, Closure<T> code)Executes the given closure and returns a Timed capturing both the closure's result and the elapsed time in nanoseconds. |
|
public static long |
timedMillis(System self, Closure<?> code)Executes the given closure and returns the elapsed time in whole milliseconds. |
|
public static long |
timedNanos(System self, Closure<?> code)Executes the given closure and returns the elapsed time in nanoseconds. |
| Methods inherited from class | Name |
|---|---|
class Object |
addShutdownHook, any, any, asBoolean, asType, clamp, clamp, collect, collect, collect, dump, each, eachMatch, eachMatch, eachWithIndex, every, every, find, find, findAll, findAll, findIndexOf, findIndexOf, findIndexValues, findIndexValues, findLastIndexOf, findLastIndexOf, findResult, findResult, findResult, findResult, getAt, getMetaClass, getMetaPropertyValues, getProperties, grep, grep, hasProperty, identity, inject, inject, inject, inject, inspect, invokeMethod, is, isCase, isNotCase, iterator, metaClass, print, print, printf, printf, println, println, println, putAt, respondsTo, respondsTo, setMetaClass, sleep, sleep, split, sprintf, sprintf, stream, takeIf, tap, toString, use, use, use, with, with, withCloseable, withCloseable, withMethodClosure, withStream, withStream, withTraits |
Get the current time in seconds
self - placeholder variable used by Groovy categories; ignored for default static methodsExecutes the given closure and returns a Timed capturing both the closure's result and the elapsed time in nanoseconds.
Timing uses System.nanoTime, which is monotonic and unaffected by wall-clock adjustments. The closure is executed synchronously on the calling thread and any exception it throws propagates unchanged.
def t = System.timed { (1..1_000).sum() }
assert t.result == 500_500
assert t.nanos >= 0
println "computed ${t.result} in ${t.millis}ms"
self - placeholder variable used by Groovy categories; ignored for default static methodscode - the closure to execute and timeT - the type of the closure's resultExecutes the given closure and returns the elapsed time in whole milliseconds.
This is a convenience for timedNanos(code) / 1_000_000. Timing uses
System.nanoTime, which is monotonic and unaffected by wall-clock
adjustments. The closure is executed synchronously on the calling thread and
any exception it throws propagates unchanged. Its result, if any, is
discarded; use System.timed when the result is also needed.
long elapsed = System.timedMillis { (1..1_000).sum() }
assert elapsed >= 0
self - placeholder variable used by Groovy categories; ignored for default static methodscode - the closure to execute and timeExecutes the given closure and returns the elapsed time in nanoseconds.
Timing uses System.nanoTime, which is monotonic and unaffected by wall-clock adjustments. The closure is executed synchronously on the calling thread and any exception it throws propagates unchanged (the elapsed time is not reported in that case). Its result, if any, is discarded; use System.timed when the result is also needed.
long elapsed = System.timedNanos { (1..1_000).sum() }
assert elapsed >= 0
self - placeholder variable used by Groovy categories; ignored for default static methodscode - the closure to execute and time