Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Index

Constructors

Properties

Methods

Constructors

Properties

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

The SuiteLikes in this {@link (Benchmark:class)}.

Methods

  • Add a SuiteLike to this {@link (Benchmark:class)}.

    example
    benchmark.addSuite(suite);
    

    Parameters

    • suite: SuiteLike

      The SuiteLike to add

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

    Returns Benchmark

    this

  • Add a SuiteLike to this {@link (Benchmark:class)} by loading it in a separate thread via its filepath.

    example
    await benchmark.addSuite(suite);
    

    Parameters

    • suite: SuiteLike

      A {@link (Suite:class)} with a filepath provided

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

    Returns Promise<Benchmark>

    this

  • Run all {@link (Suite:class)}s for this {@link (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();

    Parameters

    • Optional abortSignal: AbortSignal

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

    Returns Promise<Benchmark.Results>

    A {@link (Benchmark:namespace).Results} Map

Generated using TypeDoc