Initializes a new instance of the BasicTimer class, optionally auto-starting it.
Determines whether the timer will immediately start; default is false.
Protected field with the time value representing the moment the pausing started.
Protected field with the time value representing the sum of all previous pause times.
Protected field with the time value representing the moment the timer started.
Gets whether the timer is paused.
This property is not influenced by pauses, i.e. it will return true even when paused.
A protected property useful when overriding the timers it changes the output of timer errors in order to represent the specified name.
Protected alias to elapsedTime.
Protected alias to isRunning.
Prevents the object from counting the time until it is resumed.
Both the elapsed time and the time resulting from stop won't change during the pause, but pausedTime and totalPauseTime will.
Begins to count time, setting the start time to a value equivalent to now.
Time that represents now (or better yet, the moment the timer has started).
Generated using TypeDoc
Counts the duration of runtime operations, with pausing capabilities.
An instance of Timer is able to count the duration between its start and stop, as well as pausing, which temporarily stops the time counting. Every start-stop cycle resets the object to its default state.
See BasicTimer for a simpler timer implentation (less overhead) and StopWatch for time segmentation.
Examples
Using a single Timer to perform consecutive countings
import { Timer } from "timecount/utils"; const timer = new Timer(); while (thereAreThingsToDo) { timer.start(); doTheThings(); timer.stop().to("second"); // 0.960041 s }
Using a TimeWriter to write Timer results
import { TimeWriter } from "timecount"; const timer = new Timer(); const timeWriter = new TimeWriter({ verbose: true }); timer.start(); timeWriter.write(timer.elapsedTime, "millisecond"); // 0.54021 milliseconds doSomething(); const time = timer.stop(); timeWriter.write(time, "millisecond"); // 10156.663207 milliseconds timeWriter.write(time, "second"); // 10.156663207 seconds timeWriter.write(time, "minute"); // 0.169277720116666668 minute
Pausing and resuming the timer
const timer = new Timer(true); thingsYouWantMeasured(); // Let's say this takes 5 seconds timer.pause(); thingsYouDontWantMeasured(); // And this another 5 seconds timer.stop().to("second"); // 5 s (paused time is not counted)