Timer
The timer module provides a simple interface for timing parts of flows. It is especially useful in combination with our Analytics product allowing you to time crucial parts of your flows.
Start
Start a named timer. If you invoke this method twice with the same name (argument) you’ll reset the timer every time.
Parameter
namethe name of the timer to start
javascript
// Create and start a timer named 'myTimer'
Timer.start('myTimer');Log
Log an event on a named timer. Useful only in combination with our Analytics product. The logged event will contain the name of the timer, the milliseconds since the timer was started and the given message.
Parameter
namethe name of the timer to log an event onmessagethe message to log
Returns
The number of milliseconds since the timer was started.
javascript
// Log an event for the timer named 'myTimer' with a descriptive message
// Returns the number of milliseconds elapsed since the timer was started
Timer.log('myTimer', 'A message goes here');Stop
Stop a named timer.
Parameter
namethe name of the timer to stoplogwhether or not a message should be logged
Returns
The number of milliseconds since the timer was started.
javascript
// Stop the timer named 'myTimer' and log a final event
// Returns the total elapsed time in milliseconds since the timer was started
Timer.stop('myTimer', true);Report
Return an object reporting measured times.
Returns
Returns an object with the following properties:
namethe name of the timerstartDate and time the timer was startedlogsa list of object that represent the calls to log function. Each object containinglabelandmilliSecstopmillisec passed from start to stop, or -1 if stop was not called for the timer
Parameter
namethe name of the timer
Example
javascript
// Test timer with two log calls
Timer.start("Test");
Wait.forMilliseconds(100);
Timer.log("Test", "One" );
Wait.forMilliseconds(100);
Timer.log("Test", "Two" );
Wait.forMilliseconds(100);
Timer.stop("Test");
var report = Timer.report("Test");
// Will give a report like:
{
name: "Test",
start: "2025-10-24T09:55:53.573Z",
logs: [
{
label: "One",
milliSec: 103
},
{
label: "Two",
milliSec: 206
}
],
stop: 309
}