Allows you to time operations.
Tries to get the elapsed ms. Throws if the Stopwatch has not been started.
const w = watch();w.start();await sleep(1000);// you don't have to call stop before accessing `.elapsed()`console.log(w.elapsed()); // 1000 Copy
const w = watch();w.start();await sleep(1000);// you don't have to call stop before accessing `.elapsed()`console.log(w.elapsed()); // 1000
Reset the stopwatch.
const w = stopwatch();w.start();w.stop();w.reset();w.elapsed(); // Error: "Call `.start()` first!" Copy
const w = stopwatch();w.start();w.stop();w.reset();w.elapsed(); // Error: "Call `.start()` first!"
Start the stopwatch.
const w = stopwatch();w.start(); // start counting Copy
const w = stopwatch();w.start(); // start counting
Stop the stopwatch.
const w = stopwatch();w.start();await sleep(1000);w.stop(); // stop countingawait sleep(1000);console.log(w.elapsed()); // 1000 Copy
const w = stopwatch();w.start();await sleep(1000);w.stop(); // stop countingawait sleep(1000);console.log(w.elapsed()); // 1000
Allows you to time operations.