Package: java.lang

## [Java] Class System

- java.lang.System

-     public class System
      extends Object

  GDK enhancements for System.

  displayName:
    System
  receiverFqcn:
    java.lang.System

- - ### Nested Class Summary

    Nested classes
    Modifiers | Name | Description
    --- | --- | ---
    `static interface` | `System.Logger` | GDK enhancements for Logger.

  - ### Methods Summary

    Methods
    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.

  - ### Inherited Methods Summary

    Inherited Methods
    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`

- - ### Method Detail

    - #### public static long currentTimeSeconds(System self)

      Get the current time in seconds

      Parameters:
        `self` - placeholder variable used by Groovy categories; ignored for default static methods
      Returns:
        the difference, measured in seconds, between the current time and midnight, January 1, 1970 UTC.
      See Also:
        System.currentTimeMillis

    - #### <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.

      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"

      Parameters:
        `self` - placeholder variable used by Groovy categories; ignored for default static methods
        `code` - the closure to execute and time
      Type Parameters:
        `T` - the type of the closure's result
      Returns:
        a Timed holding the result and the elapsed nanoseconds
      See Also:
        timedNanos(System, Closure)
        timedMillis(System, Closure)
      Since:
        6.0.0

    - #### public static long timedMillis(System self, Closure<?> code)

      Executes 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

      Parameters:
        `self` - placeholder variable used by Groovy categories; ignored for default static methods
        `code` - the closure to execute and time
      Returns:
        the elapsed time in milliseconds, truncated toward zero
      See Also:
        timedNanos(System, Closure)
        timed(System, Closure)
      Since:
        6.0.0

    - #### public static long timedNanos(System self, Closure<?> code)

      Executes 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

      Parameters:
        `self` - placeholder variable used by Groovy categories; ignored for default static methods
        `code` - the closure to execute and time
      Returns:
        the elapsed time in nanoseconds
      See Also:
        timedMillis(System, Closure)
        timed(System, Closure)
      Since:
        6.0.0