Skip to content

Instantly share code, notes, and snippets.

@jpoehls
Created February 17, 2012 16:33
Show Gist options
  • Save jpoehls/1854255 to your computer and use it in GitHub Desktop.
Save jpoehls/1854255 to your computer and use it in GitHub Desktop.
Benchmark.js deferred
var Benchmark = require('benchmark');
var request = require('request');
var suite = new Benchmark.Suite;
// add tests
suite.add('Calling cow api', {
defer: true,
fn: function(deferred) {
request({
url: 'http://cowsay.morecode.org/say',
method: 'POST',
form: { format: 'text', message: "Some message." }
}, function(error, response, body) {
deferred.resolve();
});
}
})
// add listeners
.on('cycle', function(event, bench) {
console.log(String(bench));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').pluck('name'));
})
// run async
.run({ 'async': true });
Calling cow api x 6.96 ops/sec ±27.82% (33 runs sampled)
Fastest is Calling cow api
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment