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 timer started.
Gets the time elapsed since the start of the timer until now.
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.
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.
An instance of BasicTimer is able to count the duration between its start and stop. Every start-stop cycle resets the object to its default state.
See Timer if you need pausing and StopWatch for time segmentation (laps).
Examples
Using a single BasicTimer to perform consecutive countings
import { BasicTimer } from "timecount/utils"; const timer = new BasicTimer(); while (thereAreThingsToDo) { timer.start(); doTheThings(); timer.stop().to("second"); // 0.8956 s }
Using a TimeWriter to write BasicTimer results
import { TimeWriter } from "timecount"; import { BasicTimer } from "timecount/utils"; const timer = new BasicTimer(); const writer = 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