Options
All
  • Public
  • Public/Protected
  • All
Menu

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

example
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);

Hierarchy

  • Suite

Implements

Index

Constructors

Properties

Accessors

Methods

Constructors

  • Creates a new {@link (Suite:class)}.

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

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

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

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

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

    Parameters

    • name: string

      The name of the {@link (Suite:class)}

    • options: Options

      Options for the {@link (Suite:class)}

    Returns Suite

Properties

name: string

The name of this SuiteLike.

options: Options

Options for running this {@link (Suite:class)} and its warmup.

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

The tests in this {@link (Suite:class)}.

Accessors

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

    Returns undefined | string

Methods

  • addTest(testName: string, test: Test<unknown>): Suite
  • addTest(testName: string, fn: () => unknown): Suite
  • Adds a test to this {@link (Suite:class)}.

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

    suite.addTest('+', test);

    Parameters

    • testName: string

      The name of the test

    • test: Test<unknown>

      The test to add

    Returns Suite

    this

  • Creates and adds a test to this {@link (Suite:class)}.

    example
    suite.addTest('+', () => 'a' + 'b');
    

    Parameters

    • testName: string

      The name of the test

    • fn: () => unknown

      The function to run

        • (): unknown
        • Returns unknown

    Returns Suite

    this

  • Runs this {@link (Suite:class)} using {@link (Suite:class).options}.

    example
    const results = await suite.run();
    
    example

    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();

    Parameters

    • Optional abortSignal: AbortSignal

    Returns Promise<Suite.Results>

    The results of running this {@link (Suite:class)}

Generated using TypeDoc