Helper to record the amount of time elapsed between 2 points during execution.

const stopwatch = new Stopwatch();

stopwatch.start();

const elapsed = stopwatch.end();
const stopwatch = Stopwatch.start();

const elapsed = stopwatch.end();

Constructors

Accessors

Methods

Constructors

Accessors

  • get started(): boolean
  • If this stopwatch was started at any some point. This will return true even if the stopwatch is stopped.

    Time complexity: O(1)

    Space complexity: O(1)

    Returns boolean

    const stopwatch = new Stopwatch();
    console.log(stopwatch.started); // false

    stopwatch.start();
    console.log(stopwatch.started); // true

Methods

  • Return the duration elapsed since the start.

    Time complexity: O(1)

    Space complexity: O(1)

    Returns number

    The amount of time elapsed in milliseconds.

    const elapsed = stopwatch.end();
    
  • Start recording the duration of this stopwatch.

    Time complexity: O(1)

    Space complexity: O(1)

    Returns void

    stopwatch.start();
    
  • Create a new stopwatch and start it.

    Time complexity: O(1)

    Space complexity: O(1)

    Returns Stopwatch

    const stopwatch = Stopwatch.start();