Class: Timer
A class to create, start, and stop named timers that measure elapsed time in milliseconds.
Methods
elapsed()
static
elapsed(name
):number
Returns the total time elapsed, in milliseconds, of the timer.
Parameters
• name: string
The name of the timer whose elapsed duration is requested
Returns
number
Remarks
The total time elapsed will include all durations from multiple starts and stops of the timer, if applicable. A timer's elapsed duration can be read while it is in started or stopped state. The method throws an error if a timer with the given name does not exist.
Defined in
Timer.ts:134
exists()
static
exists(name
):boolean
Checks if a timer of the given name exists.
Parameters
• name: string
The name of the timer to check for existence
Returns
boolean
boolean
Remarks
The method checks if there is a timer with the given name.
Defined in
Timer.ts:191
new()
static
new(name
):void
Creates, but does not start, a new millisecond-resolution timer based on performance.now().
Parameters
• name: string
The name of the timer to be started
Returns
void
Remarks
If a timer with the given name already exists, it will be created and set back to zero, but not started.
Defined in
Timer.ts:47
now()
static
now():number
Aliases performance.now()
Returns
number
Remarks
The m2c2kit Timer class is designed to measure elapsed durations after a designated start point for a uniquely named timer. However, if a timestamp based on the time origin is needed, this method can be used.
Defined in
Timer.ts:34
remove()
static
remove(name
):void
Removes a timer.
Parameters
• name: string
The name of the timer to be removed
Returns
void
Remarks
After removal, no additional methods can be used with a timer of the given name, other than to create a new timer with the given name, whose duration will be set at 0 again. The method throws an error if a timer with the given name does not exist.
Defined in
Timer.ts:160
removeAll()
static
removeAll():void
Remove all timers.
Returns
void
Remarks
This method will remove any timers in a started or stopped state. This method is idempotent; method is safe to call even if there are no timers to remove; no errors are thrown if there are not any timers that can be removed.
Defined in
Timer.ts:179
start()
static
start(name
):void
Starts a stopped millisecond-resolution timer based on performance.now().
Parameters
• name: string
The name of the timer to be started
Returns
void
Remarks
The method throws an error if a timer with the given name does not exist or is not in a stopped state.
Defined in
Timer.ts:77
startNew()
static
startNew(name
):void
Creates and starts a new millisecond-resolution timer based on performance.now().
Parameters
• name: string
The name of the timer to be started
Returns
void
Remarks
If a timer with the given name already exists, it will be created, set back to zero, and started.
Defined in
Timer.ts:63
stop()
static
stop(name
):void
Stops a timer.
Parameters
• name: string
The name of the timer to be stopped
Returns
void
Remarks
The method throws an error if a timer with the given name is already in a stopped state, or if a timer with the given name has not been started.
Defined in
Timer.ts:104