Skip to content

Instantly share code, notes, and snippets.

@zzarcon
Created March 13, 2016 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zzarcon/b889a836d426d315b1f7 to your computer and use it in GitHub Desktop.
Save zzarcon/b889a836d426d315b1f7 to your computer and use it in GitHub Desktop.
Palindrome benchmark
var Benchmark = require('benchmark');
var palindromeC = require('bindings')('palindrome.node');
var palindromeJs = require('./palindrome.js');
var suite = new Benchmark.Suite;
var str = 'a man a plan a cat a ham a yak a yam a hat a canal panama';
suite
.add('Javascript palindrome', function() {
palindromeJs(str);
})
.add('C palindrome', function() {
palindromeC(str);
})
.on('cycle', cycle)
.on('complete', complete)
.run({ 'async': true });
function cycle(event) {
console.log(String(event.target));
}
function complete(a,b) {
console.log('Fastest: ' + this.filter('fastest').map('name'));
console.log('Slowest: ' + this.filter('slowest').map('name'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment