Helper to record the amount of time elapsed between 2 points during execution.
const stopwatch = new Stopwatch();stopwatch.start();const elapsed = stopwatch.end(); Copy
const stopwatch = new Stopwatch();stopwatch.start();const elapsed = stopwatch.end();
const stopwatch = Stopwatch.start();const elapsed = stopwatch.end(); Copy
const stopwatch = Stopwatch.start();const elapsed = stopwatch.end();
If this stopwatch was started at any some point. This will return true even if the stopwatch is stopped.
true
Time complexity: O(1)
Space complexity: O(1)
const stopwatch = new Stopwatch();console.log(stopwatch.started); // falsestopwatch.start();console.log(stopwatch.started); // true Copy
const stopwatch = new Stopwatch();console.log(stopwatch.started); // falsestopwatch.start();console.log(stopwatch.started); // true
Return the duration elapsed since the start.
The amount of time elapsed in milliseconds.
const elapsed = stopwatch.end(); Copy
const elapsed = stopwatch.end();
Start recording the duration of this stopwatch.
stopwatch.start(); Copy
stopwatch.start();
Static
Create a new stopwatch and start it.
const stopwatch = Stopwatch.start(); Copy
const stopwatch = Stopwatch.start();
Helper to record the amount of time elapsed between 2 points during execution.
Example
Example