Skip to content

indutny/bencher

Repository files navigation

@indutny/bencher

npm CI Status

Simple JavaScript benchmarking tool inspired by my bad understanding of how Criterion.rs works.

Disclaimer

Let's be honest, I'm terrible at statistics. This approach that I took here is probably incorrect, but the results appear to be stable enough so I'm happy to use it for my personal projects.

Any ideas on improving the algorithm are very welcome!

Installation

npm install -g @indutny/bencher

Usage

// benchmark.js
export const name = 'runner';

// Function to benchmark
export default () => {
  let sum = 0;
  for (let i = 0; i < 1e6; i++) {
    sum += i;
  }

  // Make sure to return a side-effect value (possibly a result of the
  // run) to ensure that the pure function calls are not optimized out by the
  // JIT compiler.
  return sum;
};
$ bencher benchmark.js
runner: 1’037.8 ops/sec (±18.8, p=0.001, n=98)

LICENSE

This software is licensed under the MIT License.