Created
August 15, 2020 07:53
-
-
Save TheAthlete/893eb4770feeb4603d632178328a18ce to your computer and use it in GitHub Desktop.
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
var Benchmark = require('benchmark'); | |
var suite = new Benchmark.Suite; | |
let dominoes = [[1,1],[2,2],[1,1],[1,2],[1,2],[1,1]]; | |
// add tests | |
suite.add('sort-join', function() { | |
for (let d of dominoes) { | |
[...d].sort((a, b) => a - b).join(''); | |
} | |
}) | |
.add('ternary', function() { | |
for (let d of dominoes) { | |
d[0] < d[1] ? d[0] + '' + d[1] : d[1] + '' + d[0]; | |
} | |
}) | |
.add('ternary-numeric', function() { | |
for (let d of dominoes) { | |
d[0] < d[1] ? d[0] + d[1] : d[1] + d[0]; | |
} | |
}) | |
// 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