benchmark-json-reporter

1.1.0 • Public • Published

benchmark-json-reporter

Returns an array with the data for every benchmark of the suite. The default callback writes it to the <rootFolder>/benchmarks/<suiteName>.json file. No npm dependencies.

It works only in NodeJS.

Installation

yarn add benchmark benchmark-json-reporter

Or

npm install --save benchmark benchmark-json-reporter

Function firm

type jsonReportCallback = (
  result{
    sysinfo: any;
    benchmarks: any[];
  },
  sysHashstring,
  namestring,
  folderstring,
) => void
type jsonReporter = (
  suiteBenchmark.Suite,
  config?: {
    folder?: string,
    callback?: jsonReportCallback,
  },
) => void

Usage

Using the default callback

const Benchmark = require('benchmark');
const jsonReporter = require('benchmark-json-reporter');
 
const suite = new Benchmark.Suite('my-bench-suite');
 
// Just this
jsonReporter(suite);
 
suite
  .add('bench-name-1', () => {
    // Faster heavy process
  })
  // ...
  .add('bench-name-n', () => {
    // Slower heavy process
  })
  // run async
  .run({ async: true });

Using a custom callback

const Benchmark = require('benchmark');
const jsonReporter = require('benchmark-json-reporter');
 
const suite = new Benchmark.Suite('my-bench-suite');
 
// Just this
jsonReporter(suite, {
  callback(result, hashId, name, folder) {
    // 1. Connect to a database
    const connection = new SomeEndPoint();
    // 2. Store the sysinfo with the hashId as a main ID
    connection
      .getById(hashId)
      .update({ sysinfo: result.sysinfo })
      .then(() => 
        // 3. Store the benchmarks
        Promise.all(
          benchs.map(bench =>
            // For each benchmark, push the result into the collection
            connection
              .getById(hashId)
              .getProp('benchmarks')
              .getCollection(bench.timestamp).push(bench),
          )
        )
      ).then(() => {
        // 4. Close the database connection
        connection.close();
      });
    // 5. Profit.
  },
});
 
suite
  .add('bench-name-1', () => {
    // Faster heavy process
  })
  // ...
  .add('bench-name-n', () => {
    // Slower heavy process
  })
  // run async
  .run({ async: true });

Package Sidebar

Install

npm i benchmark-json-reporter

Weekly Downloads

0

Version

1.1.0

License

MIT

Unpacked Size

7.24 kB

Total Files

6

Last publish

Collaborators

  • lgraziani2712