tinybench - v6.0.1
    Preparing search index...

    Class Bench

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

    Hierarchy

    • EventTarget
      • Bench

    Implements

    Index

    Constructors

    Properties

    addEventListener: <K extends BenchEvents>(
        type: K,
        listener: EventListener<K> | EventListenerObject<K, "bench"> | null,
        options?: boolean | AddEventListenerOptions,
    ) => void

    The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

    MDN Reference

    concurrency: "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.
    iterations: number

    The amount of executions per task.

    name: string | undefined

    The benchmark name.

    now: () => number

    A function to get a timestamp.

    removeEventListener: <K extends BenchEvents>(
        type: K,
        listener: EventListener<K> | EventListenerObject<K, "bench"> | null,
        options?: boolean | EventListenerOptions,
    ) => void

    Removes a previously registered event listener.

    retainSamples: boolean

    Should samples be retained for further custom processing

    runtime: JSRuntime

    The JavaScript runtime environment.

    runtimeVersion: string

    The JavaScript runtime version.

    setup: (task: Task, mode: "warmup" | "run") => void | Promise<void>

    A setup function that runs before each task execution.

    signal?: AbortSignal

    An AbortSignal to cancel the benchmark.

    teardown: (task: Task, mode: "warmup" | "run") => void | Promise<void>

    A teardown function that runs after each task execution.

    threshold: number

    The maximum number of concurrent tasks to run

    Number.POSITIVE_INFINITY
    
    throws: boolean

    Whether to throw an error if a task function throws

    false
    
    time: number

    The amount of time to run each task.

    timestampProvider: TimestampProvider

    A timestamp provider and its related functions.

    warmup: boolean

    Whether to warmup the tasks before running them

    warmupIterations: number

    The amount of warmup iterations per task.

    warmupTime: number

    The amount of time to warmup each task.

    Accessors

    • get tasks(): Task[]

      The tasks as an array.

      Returns Task[]

      An array containing all benchmark tasks

    Methods

    • Adds a benchmark task to the task map.

      Parameters

      • name: string

        the task name

      • fn: Fn

        the task function

      • fnOpts: FnOptions = {}

        the task function options

      Returns this

      the Bench instance

      when a task with the same name already exists

    • The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().

      MDN Reference

      Parameters

      • event: Event

      Returns boolean

    • Gets a task based on the task name.

      Parameters

      • name: string

        the task name

      Returns Task | undefined

      the Task instance or undefined if not found

    • Removes a benchmark task from the task map.

      Parameters

      • name: string

        the task name

      Returns this

      the Bench instance

    • Resets all tasks and removes their results.

      Returns void

    • Runs the added benchmark tasks.

      Returns Promise<Task[]>

      the tasks array

    • Runs the added benchmark tasks synchronously.

      Returns Task[]

      the tasks array

    • Returns the tasks results as a table.

      Parameters

      • convert: ConsoleTableConverter = defaultConvertTaskResultForConsoleTable

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

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

      the tasks results as an array of table records