A benchmark which has many SuiteLikes.

Example

import { Benchmark, Suite } from '@jonahsnider/benchmark';

const benchmark = new Benchmark();

const suite = new Suite('concatenation', { warmup: { durationMs: 10_000 }, run: { durationMs: 10_000 } })
.addTest('+', () => 'a' + 'b')
.addTest('templates', () => `${'a'}${'b'}`)
.addTest('.concat()', () => 'a'.concat('b'));

benchmark.addSuite(suite);

const results = await benchmark.run();

console.log(results);

Hierarchy

  • Benchmark

Constructors

Properties

Methods

Constructors

Properties

suites: ReadonlyMap<string, SuiteLike> = ...

Methods

  • Run all (Suite:class)s for this (Benchmark:class).

    Example

    const results = await benchmark.runSuites();
    

    Example

    Using an AbortSignal to cancel the benchmark:

    const ac = new AbortController();
    const signal = ac.signal;

    benchmark
    .runSuites(signal)
    .then(console.log)
    .catch(error => {
    if (error.name === 'AbortError') {
    console.log('The benchmark was aborted');
    }
    });

    ac.abort();

    Returns

    A (Benchmark:namespace).Results Map

    Parameters

    • Optional abortSignal: AbortSignal

      An optional AbortSignal that can be used to cancel the running suites

    Returns Promise<Benchmark.Results>

Generated using TypeDoc