Created
March 28, 2016 16:16
-
-
Save tmcw/034157189814d0748b58 to your computer and use it in GitHub Desktop.
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 suite = new Benchmark.Suite; | |
var strings = [ | |
'hi, there', | |
'you scoundrel', | |
'cheers', | |
'cheers, you', | |
'cheers, you, there', | |
'lol', | |
'donuts' | |
]; | |
// add tests | |
suite | |
.add('split', function() { | |
strings.map(function(str) { | |
return str.split(',')[0] | |
}); | |
}) | |
.add('indexOf', function() { | |
strings.map(function(str) { | |
var firstC = str.indexOf(','); | |
return firstC === -1 ? str : str.substr(0, firstC); | |
}); | |
}) | |
// add listeners | |
.on('cycle', function(event) { | |
console.log(String(event.target)); | |
}) | |
.on('complete', function() { | |
console.log('Fastest is ' + this.filter('fastest').map('name')); | |
}) | |
// run async | |
.run({ 'async': true }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment