Method gauge()


Method gauge

float gauge(mixed expression)

Description

Gauge the CPU time that the expression takes to evaluate.

Parameter expression

Expression to evaluate.

Analogous to catch(), there are two syntaxes:

float elapsed = gauge(expression);

and

float elapsed = gauge {
      // Code block
    };

Where the latter is more versatile and more common.

Returns

Returns the time in seconds as a float.

Note

This measures CPU time consumed (via gethrvtime()), not wall-clock time. Time spent blocked on I/O, sleeping, or waiting for another thread is not included; e.g. gauge { sleep(1.0); } returns a value close to 0.0, not 1.0.

Note

gauge is not a function, but a special form. It is thus not valid to pass as a function.

See also

catch(), gethrvtime()