Skip to content

Instantly share code, notes, and snippets.

@vatson
Created December 30, 2017 12:19
Show Gist options
  • Save vatson/e1b83b12601278efc9a8afdba111e1d5 to your computer and use it in GitHub Desktop.
Save vatson/e1b83b12601278efc9a8afdba111e1d5 to your computer and use it in GitHub Desktop.
Benchmark with repeat and without
const Benchmark = require('benchmark');
const suite = new Benchmark.Suite;
suite.add('Without repeat', function() {
const fiveLine = (s) => {
s = s.trim();
return `${s}\n${s}${s}\n${s}${s}${s}\n${s}${s}${s}${s}\n${s}${s}${s}${s}${s}`;
}
fiveLine('sdfdsfsd')
fiveLine(' sdfdsfsdS sas asdas asaa ')
fiveLine(' sdfdsfsdS sas asdas asaa ')
fiveLine(' sdfdsfsdS sas asdas asaa ')
})
.add('With repeat', function() {
const fiveLine = (s) => {
s = s.trim();
return `${s.repeat(1)}\n${s.repeat(2)}\n${s.repeat(3)}\n${s.repeat(4)}\n${s.repeat(5)}`
}
fiveLine('sdfdsfsd')
fiveLine(' sdfdsfsdS sas asdas asaa ')
fiveLine(' sdfdsfsdS sas asdas asaa ')
fiveLine(' sdfdsfsdS sas asdas asaa ')
})
// 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