1 import { bench, group, run } from 'tatami-ng'
5 * @param numberOfWorkers
7 function generateWorkersArray (numberOfWorkers) {
8 return [...Array(numberOfWorkers).keys()]
11 const workers = generateWorkersArray(60)
18 function roundRobinTernaryOffByOne () {
20 workers.length - 1 === nextWorkerIndex ? 0 : nextWorkerIndex + 1
21 return workers[nextWorkerIndex]
27 function roundRobinTernaryWithNegation () {
29 !nextWorkerIndex || workers.length - 1 === nextWorkerIndex
32 return workers[nextWorkerIndex]
38 function roundRobinTernaryWithPreChoosing () {
39 const chosenWorker = workers[nextWorkerIndex]
41 workers.length - 1 === nextWorkerIndex ? 0 : nextWorkerIndex + 1
48 function roundRobinIncrementModulo () {
49 const chosenWorker = workers[nextWorkerIndex]
51 nextWorkerIndex %= workers.length
55 group('Round robin tasks distribution', () => {
56 bench('Ternary off by one', () => {
58 roundRobinTernaryOffByOne()
60 bench('Ternary with negation', () => {
62 roundRobinTernaryWithNegation()
64 bench('Ternary with pre-choosing', () => {
66 roundRobinTernaryWithPreChoosing()
68 bench('Increment+Modulo', () => {
70 roundRobinIncrementModulo()
74 await run({ units: true })