Last active
April 12, 2016 19:31
-
-
Save jclem/e85a026c6d9dde57ba273f3a12d95123 to your computer and use it in GitHub Desktop.
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 suite = new Benchmark.Suite(); | |
suite.add('String#match', function() { | |
var match = 'foo,bar,baz'.match(/^(foo),(bar),(baz)/); | |
var foo = match[1]; | |
var bar = match[2]; | |
var baz = match[3]; | |
}).add('String#split', function() { | |
var split = 'foo,bar,baz'.split(','); | |
var foo = split[0]; | |
var bar = split[1]; | |
var baz = split[2]; | |
}).add('Slice, String#split', function() { | |
var string = 'foobar,baz'; | |
var foo = string.slice(0,3); | |
var split = string.slice(3).split(','); | |
var bar = split[0]; | |
var baz = split[1]; | |
}).on('cycle', function(event) { | |
console.log(String(event.target)); | |
}).on('complete', function() { | |
console.log('Fastest is ' + this.filter('fastest').map('name')); | |
}).run(); |
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
{ | |
"dependencies": { | |
"benchmark": "^2.1.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment