tinybench - v4.0.1
    Preparing search index...

    Class Bench

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

    Hierarchy

    • EventTarget
      • Bench
    Index

    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.
    name?: string

    The benchmark name.

    opts: Readonly<BenchOptions>

    The options.

    runtime: JSRuntime | "unknown"

    The JavaScript runtime environment.

    runtimeVersion: string

    The JavaScript runtime version.

    threshold: number = Number.POSITIVE_INFINITY

    The maximum number of concurrent tasks to run

    Number.POSITIVE_INFINITY
    

    Accessors

    • get results(): (undefined | Readonly<TaskResult>)[]

      tasks results as an array

      Returns (undefined | Readonly<TaskResult>)[]

      the tasks results as an array

    Methods

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

      if the task already exists

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

    • 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 tasks and remove their result

      Returns void

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

      Returns Promise<Task[]>

      the tasks array

    • run the added tasks that were registered using the add method (sync version)

      Returns 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

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

      the tasks results as an array of table records