Timer

About

Instances of this class are useful to keep track of how much time has passed since they were created.

API

constructor()

cs.js.Timer.new({ label: Text })

Creates a new millisecond timer. If label is passed and is non-empty, it will be used as a prefix in .alert() and .toString().


.alert()

.alert({ divisor: Integer })

Shows the result of This.toString($divisor) in an alert.


.time

.time : Integer

Returns the number of milliseconds that has elapsed since this timer was created. This property is read-only.


.toString()

.toString({ divisor : Integer) : Text

Returns a string with the number of milliseconds since the timer was created. If divisor is passed and is non-zero, the number of milliseconds is divided by divisor. This is useful, for example, when you want to show the number of milliseconds per iteration of a loop.

If a label was set in the constructor, it will be used as a prefix for the returned string.

Example

$timer:=cs.js.Timer.new()
foobar()
ALERT("foobar() took "+$timer.toString())
// => "foobar took 251 ms"
Last Updated:
Contributors: Aparajita