let nextWorkerIndex
-function chooseWorkerTernaryOffByOne () {
+function roundRobinTernaryOffByOne () {
nextWorkerIndex =
workers.length - 1 === nextWorkerIndex ? 0 : nextWorkerIndex + 1
return workers[nextWorkerIndex]
}
-function chooseWorkerTernaryWithNegation () {
+function roundRobinTernaryWithNegation () {
nextWorkerIndex =
!nextWorkerIndex || workers.length - 1 === nextWorkerIndex
? 0
return workers[nextWorkerIndex]
}
-function chooseWorkerTernaryWithPreChoosing () {
+function roundRobinTernaryWithPreChoosing () {
const chosenWorker = workers[nextWorkerIndex]
nextWorkerIndex =
workers.length - 1 === nextWorkerIndex ? 0 : nextWorkerIndex + 1
return chosenWorker
}
-function chooseWorkerIncrementModulo () {
+function roundRobinIncrementModulo () {
const chosenWorker = workers[nextWorkerIndex]
nextWorkerIndex++
nextWorkerIndex %= workers.length
suite
.add('Ternary off by one', function () {
nextWorkerIndex = 0
- chooseWorkerTernaryOffByOne()
+ roundRobinTernaryOffByOne()
})
.add('Ternary with negation', function () {
nextWorkerIndex = 0
- chooseWorkerTernaryWithNegation()
+ roundRobinTernaryWithNegation()
})
.add('Ternary with pre-choosing', function () {
nextWorkerIndex = 0
- chooseWorkerTernaryWithPreChoosing()
+ roundRobinTernaryWithPreChoosing()
})
.add('Increment+Modulo', function () {
nextWorkerIndex = 0
- chooseWorkerIncrementModulo()
+ roundRobinIncrementModulo()
})
.on('cycle', function (event) {
console.log(event.target.toString())