I\'d like to use the Benchmark.js module to test some asynchronous code written in node.js. Specifically, I want to fire ~10,000 requests to two servers (one written in nod
It's not very well documented, but here's a PoC:
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite();
suite.add(new Benchmark('foo', {
// a flag to indicate the benchmark is deferred
defer : true,
// benchmark test function
fn : function(deferred) {
setTimeout(function() {
deferred.resolve();
}, 200);
}
})).on('complete', function() {
console.log(this[0].stats);
}).run();
Benchmark.js v2 slightly changes the syntax:
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
suite.add('foo', {
defer: true,
fn: function (deferred) {
setTimeout(function() {
deferred.resolve();
}, 200);
}
}).on('complete', function () {
console.log(this[0].stats)
}).run()