1 import { bench, group, run } from 'tatami-ng'
5 * @param numberOfWorkers
8 function generateWorkersArray (numberOfWorkers) {
9 return [...Array(numberOfWorkers).keys()]
12 const workers = generateWorkersArray(60)
19 function roundRobinTernaryOffByOne () {
21 workers.length - 1 === nextWorkerIndex ? 0 : nextWorkerIndex + 1
22 return workers[nextWorkerIndex]
28 function roundRobinTernaryWithNegation () {
30 !nextWorkerIndex || workers.length - 1 === nextWorkerIndex
33 return workers[nextWorkerIndex]
39 function roundRobinTernaryWithPreChoosing () {
40 const chosenWorker = workers[nextWorkerIndex]
42 workers.length - 1 === nextWorkerIndex ? 0 : nextWorkerIndex + 1
49 function roundRobinIncrementModulo () {
50 const chosenWorker = workers[nextWorkerIndex]
52 nextWorkerIndex %= workers.length
56 group('Round robin tasks distribution', () => {
57 bench('Ternary off by one', () => {
59 roundRobinTernaryOffByOne()
61 bench('Ternary with negation', () => {
63 roundRobinTernaryWithNegation()
65 bench('Ternary with pre-choosing', () => {
67 roundRobinTernaryWithPreChoosing()
69 bench('Increment+Modulo', () => {
71 roundRobinIncrementModulo()
75 await run({ units: true })