Skip to content

Instantly share code, notes, and snippets.

@kenany
Created September 7, 2013 02:05
Show Gist options
  • Select an option

  • Save kenany/6472179 to your computer and use it in GitHub Desktop.

Select an option

Save kenany/6472179 to your computer and use it in GitHub Desktop.
factorial in Node.js benchmark
var Benchmark = require('benchmark');
function factorial1(v) {
return v === 0 ? 1 : v * factorial1(v - 1);
}
function factorial2(v) {
return v ? v * factorial2(v - 1) : 1;
}
var suite = new Benchmark.Suite;
suite
.add('factorial1', function() {
factorial1(21);
})
.add('factorial2', function() {
factorial2(21);
})
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', function() {
console.log('\nFastest is ' + this.filter('fastest').pluck('name'));
})
.run({'async': true});
@tpai
Copy link
Copy Markdown

tpai commented Jul 21, 2017

.pluck should be .map for the benchmark 2.1.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment