tinybench - v6.0.1
    Preparing search index...

    Interface BenchLike

    Used to decouple Bench and Task

    interface BenchLike {
        addEventListener: <K extends BenchEvents>(
            type: K,
            listener:
                | EventListener<K, "bench">
                | EventListenerObject<K, "bench">
                | null,
            options?: boolean | AddEventListenerOptions,
        ) => void;
        concurrency: Concurrency;
        iterations: number;
        now: NowFn;
        removeEventListener: <K extends BenchEvents>(
            type: K,
            listener:
                | EventListener<K, "bench">
                | EventListenerObject<K, "bench">
                | null,
            options?: boolean | EventListenerOptions,
        ) => void;
        retainSamples: boolean;
        runtime: JSRuntime;
        runtimeVersion: string;
        setup: (task: Task, mode: "warmup" | "run") => void | Promise<void>;
        signal?: AbortSignal;
        teardown: (task: Task, mode: "warmup" | "run") => void | Promise<void>;
        threshold: number;
        throws: boolean;
        time: number;
        timestampProvider: TimestampProvider;
        warmup: boolean;
        warmupIterations: number;
        warmupTime: number;
        dispatchEvent(event: Event): boolean;
    }

    Hierarchy

    • EventTarget
      • BenchLike

    Implemented by

    Index

    Properties

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

    Adds a listener for the specified event type.

    concurrency: Concurrency

    Executes tasks concurrently based on the specified concurrency mode, if set.

    • 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.

    now: NowFn

    A function to get a timestamp.

    removeEventListener: <K extends BenchEvents>(
        type: K,
        listener:
            | EventListener<K, "bench">
            | 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

    throws: boolean

    Whether to throw an error if a task function throws

    time: number

    The amount of time to run each task.

    timestampProvider: TimestampProvider

    The timestamp provider used by the benchmark.

    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.

    Methods

    • 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