Class Bench

The Bench class keeps track of the benchmark tasks and controls them.

Hierarchy

  • EventTarget
    • Bench

Constructors

Properties

concurrency: null | "task" | "bench" = null

Executes tasks concurrently based on the specified concurrency mode.

  • When mode is set to null (default), concurrency is disabled.
  • When mode is set to 'task', each task's iterations (calls of a task function) run concurrently.
  • When mode is set to 'bench', different tasks within the bench run concurrently. Concurrent cycles.
iterations: number = defaultMinimumIterations
name?: string

The benchmark name.

now: (() => number) = now

Type declaration

    • (): number
    • Returns the current high resolution millisecond timestamp, where 0 represents the start of the current node process.

      Returns number

      v8.5.0

runtime: JSRuntime | "unknown"

The JavaScript runtime environment.

runtimeVersion: string

The JavaScript runtime version.

setup: Hook
signal?: AbortSignal
teardown: Hook
threshold: number = Number.POSITIVE_INFINITY

The maximum number of concurrent tasks to run

Number.POSITIVE_INFINITY
throws: boolean = false
time: number = defaultMinimumTime
warmup: boolean = true
warmupIterations: number = defaultMinimumWarmupIterations
warmupTime: number = defaultMinimumWarmupTime

Accessors

Methods

  • add a benchmark task to the task map

    Parameters

    • name: string

      the task name

    • fn: Fn

      the task function

    • opts: FnOptions = {}

      the task options

    Returns this

    the Bench instance

  • Adds a new handler for the type event. Any given listener is added only once per type and per capture option value.

    If the once option is true, the listener is removed after the next time a type event is dispatched.

    The capture option is not used by Node.js in any functional way other than tracking registered event listeners per the EventTarget specification. Specifically, the capture option is used as part of the key when registering a listener. Any individual listener may be added once with capture = false, and once with capture = true.

    Type Parameters

    Parameters

    • type: K
    • listener: BenchEventsMap[K]
    • Optionaloptions: boolean | AddEventListenerOptions

    Returns void

  • Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.

    Parameters

    • event: Event

    Returns boolean

  • get a task based on the task name

    Parameters

    • name: string

      the task name

    Returns undefined | Task

    the task

  • remove a benchmark task from the task map

    Parameters

    • name: string

      the task name

    Returns this

    the Bench instance

  • Removes the event listener in target's event listener list with the same type, callback, and options.

    Type Parameters

    Parameters

    • type: K
    • listener: BenchEventsMap[K]
    • Optionaloptions: boolean | EventListenerOptions

    Returns void

  • reset each task and remove its result

    Returns void

  • run the added tasks that were registered using the add method

    Returns Promise<Task[]>

    the tasks array

  • table of the tasks results

    Parameters

    • Optionalconvert: ((task: Task) => Record<string, undefined | string | number>)

      an optional callback to convert the task result to a table record

        • (task): Record<string, undefined | string | number>
        • Parameters

          Returns Record<string, undefined | string | number>

    Returns (null | Record<string, undefined | string | number>)[]

    the tasks results as an array of table records