build(deps-dev): apply updates
[poolifier.git] / benchmarks / worker-selection / round-robin.mjs
index b724a04ad5f6acc009bb86b0fd7e32318757a07b..64ea78da719cf0ef0607bfa4f8e27cb0e4977388 100644 (file)
@@ -1,5 +1,10 @@
-import Benchmark from 'benny'
+import { bench, group, run } from 'tatami-ng'
 
+/**
+ *
+ * @param numberOfWorkers
+ * @returns
+ */
 function generateWorkersArray (numberOfWorkers) {
   return [...Array(numberOfWorkers).keys()]
 }
@@ -8,12 +13,18 @@ const workers = generateWorkersArray(60)
 
 let nextWorkerIndex
 
+/**
+ * @returns
+ */
 function roundRobinTernaryOffByOne () {
   nextWorkerIndex =
     workers.length - 1 === nextWorkerIndex ? 0 : nextWorkerIndex + 1
   return workers[nextWorkerIndex]
 }
 
+/**
+ * @returns
+ */
 function roundRobinTernaryWithNegation () {
   nextWorkerIndex =
     !nextWorkerIndex || workers.length - 1 === nextWorkerIndex
@@ -22,6 +33,9 @@ function roundRobinTernaryWithNegation () {
   return workers[nextWorkerIndex]
 }
 
+/**
+ * @returns
+ */
 function roundRobinTernaryWithPreChoosing () {
   const chosenWorker = workers[nextWorkerIndex]
   nextWorkerIndex =
@@ -29,6 +43,9 @@ function roundRobinTernaryWithPreChoosing () {
   return chosenWorker
 }
 
+/**
+ * @returns
+ */
 function roundRobinIncrementModulo () {
   const chosenWorker = workers[nextWorkerIndex]
   nextWorkerIndex++
@@ -36,24 +53,23 @@ function roundRobinIncrementModulo () {
   return chosenWorker
 }
 
-Benchmark.suite(
-  'Round robin tasks distribution',
-  Benchmark.add('Ternary off by one', () => {
+group('Round robin tasks distribution', () => {
+  bench('Ternary off by one', () => {
     nextWorkerIndex = 0
     roundRobinTernaryOffByOne()
-  }),
-  Benchmark.add('Ternary with negation', () => {
+  })
+  bench('Ternary with negation', () => {
     nextWorkerIndex = 0
     roundRobinTernaryWithNegation()
-  }),
-  Benchmark.add('Ternary with pre-choosing', () => {
+  })
+  bench('Ternary with pre-choosing', () => {
     nextWorkerIndex = 0
     roundRobinTernaryWithPreChoosing()
-  }),
-  Benchmark.add('Increment+Modulo', () => {
+  })
+  bench('Increment+Modulo', () => {
     nextWorkerIndex = 0
     roundRobinIncrementModulo()
-  }),
-  Benchmark.cycle(),
-  Benchmark.complete()
-)
+  })
+})
+
+await run({ units: true })