std
    Preparing search index...

    Class StopWatch

    Creates a new stopwatch instance.

    const w = new Stopwatch();

    w.start();

    await sleep(1000);

    console.log(w.elapsed()); // 1000
    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    endedAt: undefined | number = undefined
    startedAt: undefined | number = undefined

    Methods

    • Tries to get the elapsed ms. Throws if the Stopwatch has not been started.

      Returns number

      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.

      Returns void

      const w = stopwatch();

      w.start();

      w.stop();

      w.reset();

      w.elapsed(); // Error: "Call `.start()` first!"
    • Start the stopwatch.

      Returns void

      const w = stopwatch();

      w.start(); // start counting
    • Stop the stopwatch.

      Returns void

      const w = stopwatch();

      w.start();

      await sleep(1000);

      w.stop(); // stop counting

      await sleep(1000);

      console.log(w.elapsed()); // 1000