Created
March 13, 2016 15:10
-
-
Save zzarcon/b889a836d426d315b1f7 to your computer and use it in GitHub Desktop.
Palindrome benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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