A collection of (Test:class)s that are different implementations of the same thing (ex. different ways of sorting an array).

import { Suite } from '@jonahsnider/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'));

const results = await suite.run();

console.log(results);

Implements

Constructors

Properties

Accessors

Methods

Constructors

  • Creates a new (Suite:class).

    Parameters

    • name: string

      The name of the (Suite:class)

    • options: Options

      Options for the (Suite:class)

    Returns Suite

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

    const suite = new Suite('concatenation', { warmup: { durationMs: 10_000 }, run: { durationMs: 10_000 } });

    Suites that specify a filepath can be run in a separate thread in a (Benchmark:class).

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

    const suite = new Suite('concatenation', {
    warmup: { durationMs: 10_000 },
    run: { durationMs: 10_000 },
    filepath: import.meta.url
    });

Properties

name: string

The name of the (Suite:class)

options: Options

Options for running this (Suite:class) and its warmup.

tests: ReadonlyMap<string, Test<unknown>> = ...

The tests in this (Suite:class).

Accessors

  • get filepath(): undefined | string
  • This (Suite:class)'s filepath, if it was provided. Used for running the (Suite:class) in a separate thread.

    Returns undefined | string

Methods

  • Adds a test to this (Suite:class).

    Parameters

    • testName: string

      The name of the test

    • test: Test<unknown>

      The test to add

    Returns this

    this

    const test = new Test(() => 'a' + 'b');

    suite.addTest('+', test);
  • Creates and adds a test to this (Suite:class).

    Parameters

    • testName: string

      The name of the test

    • fn: (() => unknown)

      The function to run

        • (): unknown
        • Returns unknown

    Returns this

    this

    suite.addTest('+', () => 'a' + 'b');
    
  • Runs this (Suite:class) using (Suite:class).options.

    Parameters

    • OptionalabortSignal: AbortSignal

    Returns Promise<Suite.Results>

    The results of running this (Suite:class)

    const results = await suite.run();
    

    Using an AbortSignal to cancel the suite:

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

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

    ac.abort();