Initializes a new instance of the Timer class, optionally passing a configuration object as parameter.
An object with the options to configure the timer execution and output.
Gets the time span with the elapsed time so far, minus the paused time.
Gets a value representing the end time, in nanoseconds.
Gets whether or not the time counting has ended.
Gets a value representing the last time the object resumed from a pause, in nanoseconds.
Gets the output options object used by this timer.
Gets whether or not the time counting is paused.
Gets the result time span object from the time counting.
Gets a value representing the start time, in nanoseconds.
Gets whether or not the time counting has started.
Gets a value representing the total paused time, in nanoseconds.
Finishes the time counting, adjusting the time values and properties accordingly.
An object with the time span between start and end, minus the paused time.
Gets the timer total timespan, including the time it was paused.
A timespan object with the total time of the object.
Pauses the time counting.
Resumes the time counting from a paused state.
A number with the paused time, in nanoseconds.
Protected setter for the endTime property.
Protected setter for the result property.
Protected setter for the startTime property.
Starts the time counting.
Generated using TypeDoc
Represents a time counting object, that is able to determine temporal differences between start and end, inclusing pauses.
Timing and pausing
import {Timer} from "timecount"; const timer = new Timer({ autoStart: true }); // Operation code... timer.pause(); // Do something while timer is paused (like reading CLI input) cli.read(response => { // The time it takes for the user to enter is not logged timer.resume(); // And later, pause to ask another input... timer.pause(); cli.read(response2 => { timer.end(); const result = timer.result; const resultIncludingPaused = timer.getTimeIncludingPaused(); console.log(`Processing: ${result.toString()}`); console.log(`Total: ${resultIncludingPaused.toString()}`); }); });