On this page:
time
memory
time_  and_  memory
cpu_  milliseconds
real_  milliseconds
gc_  milliseconds
8.16.0.1

16.2 Measuring Time and Space🔗ℹ

 import: rhombus/measure package: rhombus-lib

expression

measure.time:

  option; ...

  body

  ...

 

option

 = 

~gc

Returns the same value(s) as the body sequence, but first prints to the current output port the amount of time elapsed during the evaluation of body sequence.

If the ~gc option is specified, then memory.gc is called before the body sequence, and time required for the garbage collection is not counted as part of the reported time.

> import rhombus/measure

> measure.time:

    for all:

      each i in 0..10000000

      "useless"

cpu time: 25 real time: 25 gc time: 0

"useless"

expression

measure.memory:

  body

  ...

Returns the same value(s) as the body sequence, but first prints to the current output port information about allocation during the evaluation of body sequence.

> import rhombus/measure

> measure.memory:

    for all:

      each i in 0..10

      [1, 2]

allocated: 800

[1, 2]

expression

measure.time_and_memory:

  option; ...

  body

  ...

Combines measure.time and measure.memory.

function

fun measure.cpu_milliseconds() :: Fixnum

 

function

fun measure.real_milliseconds() :: Flonum

 

function

fun measure.gc_milliseconds() :: Fixnum

The measure.cpu_milliseconds function returns an amount of processor time in fixnum milliseconds that has been consumed by on the underlying operating system, including both user and system time. The precision of the result is platform-specific, and since the result is a fixnum, the value increases only over a limited (though reasonably long) time on a 32-bit platform.

The measure.real_milliseconds function returns the number of milliseconds elapsed in real time since an unspecified starting time. Unlike system.milliseconds, which is sensitive to the system clock and may therefore retreat or advance more quickly than real time if the system clock is adjusted, results from measure.real_milliseconds will always advance with real time within a process, but results across processes are not comparable.

The measure.gc_milliseconds function returns the amount of processor time in fixnum milliseconds that has been consumed by garbage collection so far. This time is a portion of the time reported by measure.cpu_milliseconds, and is similarly limited.