Timer (library)
Overview
Summary
The Timer class is a very simple class designed to measure the time between two events.
Contents
Usage
It has only a few methods and properties, which keeps things simple.
Additionally, tasks can be timed using static methods directly on the Timer class itself, saving the step of instantiating a new instance of a Timer object:
Timer.start();
Timer.stop(true);
API
start()
Start the timer
start() can be called on a timer instance, or statically on the Timer class itself.
An instance example:
var timer = new Timer('Decombobulate');
timer.start();
// do some tasks
timer.stop(true);
Timer "Decombobulate" took 1.11 seconds
A static example:
Timer.start('Recombobulate');
// do some tasks
Timer.stop(print);
Timer "Recombobulate" took 1.25 seconds
stop(print)
Stop the timer
stop() can be called on a timer instance, or statically on the Timer class itself.
See the examples under start() for more information
toString()
Standard toString method
A standard trace reveals the following:
trace(timer);
[object Timer time="1.12 seconds"]
API - Properties
The following properties are available on Timer class instances:
- time - the time in English of the last-timed instance, such as 1.25 milliseconds, or 1.45 minutes
- milliseconds - the number of milliseconds of the last-timed instance
- startDate - the start Date object of the last-timed instance
- endDate - the end Date object of the last-timed instance
Comments are closed.