Timer
libraryA 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
-
startself Starts counting. -
stopself Stops counting and resets the counter to zero, so read the time before calling it. -
resetself Sets the counter back to zero without stopping it: a running timer keeps counting from zero. -
getstring Returns the counted time as text `HH:MM:SS:mmm` (hours, minutes, seconds, milliseconds), for example `00:01:05:250`. -
millisecondsnumber Returns the counted time in milliseconds. -
secondsnumber Returns the counted time in seconds, with decimals. -
minutesnumber Returns the counted time in minutes, with decimals. -
hoursnumber Returns the counted time in hours, with decimals.
start()
Section titled “start()”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
Example runs in CI
Timer.start()-- ... the work you want to measure ...print("took " .. Timer.get())print(Timer.milliseconds() >= 0)Timer.stop()stop()
Section titled “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
reset()
Section titled “reset()”Timer.reset()→self Sets the counter back to zero without stopping it: a running timer keeps counting from zero.
Returns
Timer.get()→string Returns the counted time as text `HH:MM:SS:mmm` (hours, minutes, seconds, milliseconds), for example `00:01:05:250`.
Returns
milliseconds()
Section titled “milliseconds()”Timer.milliseconds()→number Returns the counted time in milliseconds.
Returns
seconds()
Section titled “seconds()”Timer.seconds()→number Returns the counted time in seconds, with decimals.
Returns
minutes()
Section titled “minutes()”Timer.minutes()→number Returns the counted time in minutes, with decimals.
Returns
hours()
Section titled “hours()”Timer.hours()→number Returns the counted time in hours, with decimals.
Returns