Skip to main content

elapsed

Requires a captured instant and optionally a time unit. It returns the time difference between current time and previously captured time (instant) in the given unit. When no unit is given, default is milliseconds.

elapsed(instant)
# Or
elapsed(instant, timeUnit)

Parameters#

Returns#

  • No value

Time Unit#

ZWL provides values of time unit as constants in form of a read-only map. When you type timeUnit in editor, available constants are auto-completed.

Example#

# To know the time taken by following string replacement, use instant and elapsed functionsstart = instant()
text = 'Save your $$$. Now get $50 discount on every $500 spent.'pattern = '\\$(?<price>[1-9][0-9]{0,4})'replacement = 'USD${price}'replaceAll(text, pattern, replacement)
tookMicros = elapsed(start, timeUnit.microsecond)tookMillis = elapsed(start)printF('Total microseconds took by string replacement: %s', tookMicros)printF('Total milliseconds took by string replacement: %s', tookMillis)