Skip to content

Timer

library

A stopwatch for measuring how long steps of a script take. There is one timer per run. A background thread adds 1 ms to a counter every millisecond while the timer runs, so values are approximate and can lag when the agent is busy. The timer stops itself one hour after `Timer.start`. Read the time with `get`, `milliseconds`, `seconds`, `minutes` or `hours` before calling `Timer.stop`, because stopping also resets the counter to zero.

  • Kind Library, a global in every script
  • Category Utilities
  • Functions 8

Functions

  • start self Starts counting.
  • stop self Stops counting and resets the counter to zero, so read the time before calling it.
  • reset self Sets the counter back to zero without stopping it: a running timer keeps counting from zero.
  • get string Returns the counted time as text `HH:MM:SS:mmm` (hours, minutes, seconds, milliseconds), for example `00:01:05:250`.
  • milliseconds number Returns the counted time in milliseconds.
  • seconds number Returns the counted time in seconds, with decimals.
  • minutes number Returns the counted time in minutes, with decimals.
  • hours number Returns the counted time in hours, with decimals.
Timer.start()→self

Starts counting. Calling it while the timer runs keeps the current value and continues; after `Timer.stop` or `Timer.reset` it counts from zero.

Returns

self chainable The library itself, so calls can be chained.

Example runs in CI

Timer.start()
-- ... the work you want to measure ...
print("took " .. Timer.get())
print(Timer.milliseconds() >= 0)
Timer.stop()
Timer.stop()→self

Stops counting and resets the counter to zero, so read the time before calling it. Does nothing when the timer is not running.

Returns

self chainable The library itself, so calls can be chained.
Timer.reset()→self

Sets the counter back to zero without stopping it: a running timer keeps counting from zero.

Returns

self chainable The library itself, so calls can be chained.
Timer.get()→string

Returns the counted time as text `HH:MM:SS:mmm` (hours, minutes, seconds, milliseconds), for example `00:01:05:250`.

Returns

string The time as `HH:MM:SS:mmm`
Timer.milliseconds()→number

Returns the counted time in milliseconds.

Returns

number Whole milliseconds
Timer.seconds()→number

Returns the counted time in seconds, with decimals.

Returns

number Seconds, for example 1.25
Timer.minutes()→number

Returns the counted time in minutes, with decimals.

Returns

number Minutes, with decimals
Timer.hours()→number

Returns the counted time in hours, with decimals.

Returns

number Hours, with decimals