Created
December 30, 2017 12:19
-
-
Save vatson/e1b83b12601278efc9a8afdba111e1d5 to your computer and use it in GitHub Desktop.
Benchmark with repeat and without
This file contains hidden or 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
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