Nocturnal Programmer's Machine

    yet-another-benchmarking-tool
    TypeScript icon, indicating that this package has built-in type declarations

    2.0.1 • Public • Published

    Yet Another Benchmarking Tool

    A Benchmark is a set of Suites which are sets of Cases.

    When running a Benchmark, each Case is run several times.

    Yet Another Benchmarking Tool uses window.performance.now for browser or perf_hooks.performance.now for node to measure performance.

    Installation

    # NPM
    npm install yet-another-benchmarking-tool
    
    # Yarn
    yarn add yet-another-benchmarking-tool

    Running

    First, configure a suite:

    import { Benchmark, Suite } from 'yet-another-benchmarking-tool';
    
    const testArray = Array(1000).fill('foo');
    testArray[500] = 'baz';
    
    const suite = new Suite("Checking for some 'baz'", [
      ['Array.some', () => testArray.some((str) => str === 'baz')],
      [
        'for',
        () => {
          for (let i = 0, len = testArray.length; i < len; i += 1) {
            if (testArray[i] === 'baz') return true;
          }
          return false;
        },
      ],
    ]);

    Second, create a benchmark:

    const benchmark = new Benchmark([suite]);

    Third, run the benchmark:

    benchmark.run();

    Then get the output to the console:

    output example

    Install

    npm i yet-another-benchmarking-tool

    DownloadsWeekly Downloads

    24

    Version

    2.0.1

    License

    ISC

    Unpacked Size

    66.4 kB

    Total Files

    15

    Last publish

    Collaborators

    • vovaspace