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

Example

const stopwatch = new Stopwatch();

stopwatch.start();

const elapsed = stopwatch.end();

Example

const stopwatch = Stopwatch.start();

const elapsed = stopwatch.end();

Constructors

Properties

Accessors

Methods

Constructors

Properties

startTime?: bigint

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

    Example

    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.

    Example

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

    Time complexity: O(1)

    Space complexity: O(1)

    Returns void

    Example

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

    Time complexity: O(1)

    Space complexity: O(1)

    Returns Stopwatch

    Example

    const stopwatch = Stopwatch.start();