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

    The benchmark name.

    opts: Readonly<ResolvedBenchOptions>

    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

    • Type Parameters

      Parameters

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

      Returns void

    • 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

    • 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, number | string | undefined>

        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