@jonahsnider/benchmark
    Preparing search index...

    Class Benchmark

    A benchmark which has many SuiteLikes.

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

    Constructors

    Properties

    Methods

    Constructors

    Properties

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

    The SuiteLikes in this (Benchmark:class).

    Methods

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

      Parameters

      Returns this

      this

      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 }

      Returns Promise<Benchmark>

      this

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

      Parameters

      • OptionalabortSignal: AbortSignal

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

      • Optionaloptions: Benchmark.RunOptions

      Returns Promise<Benchmark.Results>

      A (Benchmark:namespace).Results Map

      const results = await benchmark.runSuites();
      

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