mb

micro-benchmark

Small benchmarking suite.

Showing:

Popularity

Downloads/wk

0

GitHub Stars

3

Maintenance

Last Commit

6yrs ago

Contributors

0

Package

Dependencies

0

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

micro-benchmark

Build Status

ES5 compatible, dependency-free benchmark suite. Runs in node.js and in a browser (IE 9+).

Installation

npm install micro-benchmark

Example

// node.js
var microBenchmark = require('micro-benchmark');

// node.js & browser
var N = 1e4;
var result = microBenchmark.suite({
    duration: 100, // optional
    maxOperations: 1000, // optional
    specs: [{
        name: 'sin(i)',
        fn: function () {
            for (var i = 0; i < N; ++i) Math.sin(i);
        }
    }, {
        name: 'sqrt(i)',
        fn: function () {
            for (var i = 0; i < N; ++i) Math.sqrt(i);
        }
    }, {
        name: 'pow(i, 2)',
        fn: function () {
            for (var i = 0; i < N; ++i) Math.pow(i, 2);
        }
    }]
});

var report = microBenchmark.report(result, { chartWidth: 10 /* 30 is default */ });
console.log(report);

// outputs
// Name         Operations per second    Average time, ms
// sqrt(i)      9.9 x 10^4               0.01                ==========>
// pow(i, 2)    9.6 x 10^4               0.01                =========>
// sin(i)       3.3 x 10^3               0.30                =>

function profile(fn, config)

  • fn - function to profile
  • config - {{ maxOperations: number, duration: number }}, optional
    • maxOperations - optional function execution number limit, default value is 1000
    • duration - optional time limit, default is 100 ms

function profileAsync(fn, config, cb)

  • fn - function to profile, should call it's first argument: next()
  • config - {{ maxOperations: number, duration: number }}, optional
    • maxOperations - optional function execution number limit, default value is 1000
    • duration - optional time limit, default is 100 ms
  • cb - callback function

function suite(config)

  • config - {{ specs: [], maxOperations: number, duration: number }}, optional
    • specs: array of objects {{ name: string, fn: function }}
      • maxOperations - optional function execution number limit, default value is 1000
      • duration - optional time limit, default is 100 ms

function suiteAsync(config, cb)

  • config - {{ specs: [], maxOperations: number, duration: number }}, optional
    • specs: array of objects {{ name: string, fn: function }}
      • maxOperations - optional function execution number limit, default value is 1000
      • duration - optional time limit, default is 100 ms
  • cb -- callback function

function report(suiteResult, config)

  • suiteResult - result of suite(...)
  • config - {{ chartWidth: number }}, optional

Testing

npm test

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial