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

Constructors

Properties

Methods

Constructors

Properties

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

The SuiteLikes in this (Benchmark:class).

Methods

  • Add a SuiteLike to this (Benchmark:class).

    Parameters

    • suite: SuiteLike

      The SuiteLike to add

    • Optional options: {
          threaded: false;
      }
      • threaded: false

    Returns this

    this

    Example

    benchmark.addSuite(suite);
    
  • Add a SuiteLike to this (Benchmark:class) by loading it in a separate thread via its filepath.

    Parameters

    • suite: SuiteLike

      A (Suite:class) with a filepath provided

    • options: {
          threaded: true;
      }
      • threaded: true

    Returns Promise<Benchmark>

    this

    Example

    await benchmark.addSuite(suite);
    
  • Run all (Suite:class)s for this (Benchmark:class).

    Parameters

    • Optional abortSignal: AbortSignal

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

    Returns Promise<Benchmark.Results>

    A (Benchmark:namespace).Results Map

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