const Benchmark = require('benchmark')
+const { LIST_FORMATTER } = require('./benchmark-utils')
const suite = new Benchmark.Suite()
-const LIST_FORMATTER = new Intl.ListFormat('en-US', {
- style: 'long',
- type: 'conjunction'
-})
+function generateWorkersArray (numberOfWorkers) {
+ return [...Array(numberOfWorkers).keys()]
+}
-const workers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
+const workers = generateWorkersArray(60)
-let nextWorkerIndex = 0
+let nextWorkerIndex
-function chooseWorkerTernary () {
+function chooseWorkerTernaryOffByOne () {
nextWorkerIndex =
workers.length - 1 === nextWorkerIndex ? 0 : nextWorkerIndex + 1
return workers[nextWorkerIndex]
}
suite
- .add('Ternary', function () {
+ .add('Ternary off by one', function () {
nextWorkerIndex = 0
- chooseWorkerTernary()
+ chooseWorkerTernaryOffByOne()
})
.add('Ternary with negation', function () {
nextWorkerIndex = 0
chooseWorkerTernaryWithNegation()
})
- .add('Ternary with PreChoosing', function () {
+ .add('Ternary with pre-choosing', function () {
nextWorkerIndex = 0
chooseWorkerTernaryWithPreChoosing()
})