tinybench - v6.1.2
    Preparing search index...

    Interface ResolvedBenchOptions

    The resolved benchmark options

    interface ResolvedBenchOptions {
        concurrency?: Concurrency;
        iterations: number;
        name?: string;
        now: NowFn;
        retainSamples?: boolean;
        setup: Hook;
        signal?: AbortSignal;
        subtractTimerOverhead: NonNullable<boolean | undefined>;
        teardown: Hook;
        threshold?: number;
        throws: NonNullable<boolean | undefined>;
        time: number;
        timestampProvider?: TimestampProvider | TimestampFns;
        warmup: NonNullable<boolean | undefined>;
        warmupIterations: number;
        warmupTime: number;
    }

    Hierarchy (View Summary)

    Index
    concurrency?: Concurrency

    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 number of times that a task should run if even the time option is finished.

    64
    
    name?: string

    Benchmark name.

    now: NowFn

    Function to get the current timestamp in milliseconds.

    retainSamples?: boolean

    Keep samples for statistics calculation

    false
    
    setup: Hook

    Setup function to run before each benchmark task (cycle)

    signal?: AbortSignal

    An AbortSignal for aborting the benchmark.

    subtractTimerOverhead: NonNullable<boolean | undefined>

    Whether to subtract an estimated timestamp provider call overhead from each raw latency sample.

    Each sample is measured as t1 - t0 around a single call to the task function, so every raw sample is inflated by approximately one timestamp provider call cost C. When this option is true, an estimate Ĉ is computed once at construction time via calibrateTimerOverhead, and max(0, raw_sample - Ĉ) is used in place of each non-overridden sample before statistics are computed.

    Statistics after correction. All fields of Statistics are derived from the clamped corrected samples, not from the raw distribution. With M denoting the raw-sample mean:

    • Clean-shift regime (X >> Ĉ). The clamp max(0, …) rarely triggers, so the correction acts as a translation by Ĉ. Location statistics (mean, min, max, all percentiles) decrease by Ĉ; absolute-unit dispersion (vr, sd, sem, moe, mad, aad) is essentially unchanged. Because rme = moe / mean, it inflates by the deterministic factor M / (M − Ĉ) whenever Ĉ > 0.
    • Sub-overhead regime (X ≈ Ĉ). A non-trivial fraction of samples clamp to 0, biasing the corrected mean upward, contracting vr/sd/sem/moe/aad, and compounding the M / (M − Ĉ) factor in rme. Once the cumulative mass of raw samples at or below Ĉ reaches a given quantile, that percentile collapses to 0; in particular p50 collapses once at least half of the raw samples satisfy raw_sample ≤ Ĉ, which then forces mad and aad toward 0. Prefer overriddenDuration for sub-overhead measurements.

    Three observable consequences of the clamp.

    1. latency.min may be exactly 0 even when no zero-duration sample was actually observed.
    2. The throughput estimator substitutes 1000 / latency.mean (or 0 when mean === 0) for every clamped sample.
    3. detectTimerSaturation criterion 'zero-dominated' cannot distinguish clamped samples from genuine zero-duration timer reads, so a 'warning' event may be dispatched in the sub-overhead regime even when the timer itself is not saturated.

    Caveat — concurrency: "task". The overhead is calibrated once at construction time with sequential timer calls. Setting both options causes the constructor (and run()) to throw, since the sequentially-calibrated estimate would not reflect the per-iteration timer call cost under concurrent execution.

    Caveat — overriddenDuration. Samples returned by the task function via overriddenDuration are intentional user values and are never modified by the correction. They are also excluded from Task.detectedResolution and from timer-saturation detection.

    On runtimes with a coarse timer (resolution >= 1 ms), the calibration returns 0 and this option becomes a no-op.

    false
    
    teardown: Hook

    Teardown function to run after each benchmark task (cycle).

    threshold?: number

    The maximum number of concurrent tasks to run

    Number.POSITIVE_INFINITY
    
    throws: NonNullable<boolean | undefined>

    Throws if a task fails.

    false
    
    time: number

    Time needed for running a benchmark task in milliseconds.

    1000
    
    timestampProvider?: TimestampProvider | TimestampFns

    The timestamp provider used by the benchmark. By default 'performance.now' will be used.

    warmup: NonNullable<boolean | undefined>

    Warmup benchmark.

    true
    
    warmupIterations: number

    Warmup iterations.

    16
    
    warmupTime: number

    Warmup time in milliseconds.

    250