bnch

A very simple (yet another) node benchmark utility

bnch

Node.js benchmark in the console

Note: this project is pretty young and the results are pretty varied atm. See TODO.

npm install bnch

Create a new file called mybenchmark.js

var bnch = require('bnch');
 
var array = new Array(65536);
array[65500] = 'mom';
 
var suite = bnch();
 
// optional, if you want to specify some preparation before each run 
suite.beforeEach(function() {
    // return the value to be used in the benchmark 
    return array.slice(0);
});
 
suite.add("Array#indexOf", function(array) {
    array.indexOf('mom');
});
 
suite.add("manual search", function(array) {
    for (var i = 0, l = array.length; i < l; i++) {
        if (array[i] === 'mom') {
            break;
        }
    }
});

And run your file using

node mybenchmark.js

And the output will look like this:

  • Isolate tests better so the results are not as varied
  • Possibly support async tests
  • Adjust sample size depending on the time each thing takes to run

MIT