Skip to content

Instantly share code, notes, and snippets.

@akira-cn
Created March 28, 2016 12:46
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 akira-cn/317bc6c2e526b62bc808 to your computer and use it in GitHub Desktop.
Save akira-cn/317bc6c2e526b62bc808 to your computer and use it in GitHub Desktop.
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
var str_long = (new Array(50000)).join('0');
var str_mid = (new Array(500)).join('0');
var str_short = (new Array(5)).join('0');
suite.add('concat#longstr', function() {
str_long + str_long;
})
.add('concat#mid', function() {
str_mid + str_mid;
})
.add('concat#shortstr', function() {
str_short + str_short;
})
// 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