repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
refactor: cleanup task function(s) handling code
[poolifier.git]
/
benchmarks
/
worker-selection
/
round-robin.mjs
diff --git
a/benchmarks/worker-selection/round-robin.mjs
b/benchmarks/worker-selection/round-robin.mjs
index 302cd2c6dffa5e5fa1a76c42f6056327a857c895..d39fd699f58016e69052f52dbcf87e6945c5f07b 100644
(file)
--- a/
benchmarks/worker-selection/round-robin.mjs
+++ b/
benchmarks/worker-selection/round-robin.mjs
@@
-1,6
+1,9
@@
-import Benchmark from 'benchmark'
-import { LIST_FORMATTER } from '../benchmarks-utils.js'
+import { bench, group, run } from 'tatami-ng'
+/**
+ *
+ * @param numberOfWorkers
+ */
function generateWorkersArray (numberOfWorkers) {
return [...Array(numberOfWorkers).keys()]
}
function generateWorkersArray (numberOfWorkers) {
return [...Array(numberOfWorkers).keys()]
}
@@
-9,12
+12,18
@@
const workers = generateWorkersArray(60)
let nextWorkerIndex
let nextWorkerIndex
+/**
+ *
+ */
function roundRobinTernaryOffByOne () {
nextWorkerIndex =
workers.length - 1 === nextWorkerIndex ? 0 : nextWorkerIndex + 1
return workers[nextWorkerIndex]
}
function roundRobinTernaryOffByOne () {
nextWorkerIndex =
workers.length - 1 === nextWorkerIndex ? 0 : nextWorkerIndex + 1
return workers[nextWorkerIndex]
}
+/**
+ *
+ */
function roundRobinTernaryWithNegation () {
nextWorkerIndex =
!nextWorkerIndex || workers.length - 1 === nextWorkerIndex
function roundRobinTernaryWithNegation () {
nextWorkerIndex =
!nextWorkerIndex || workers.length - 1 === nextWorkerIndex
@@
-23,6
+32,9
@@
function roundRobinTernaryWithNegation () {
return workers[nextWorkerIndex]
}
return workers[nextWorkerIndex]
}
+/**
+ *
+ */
function roundRobinTernaryWithPreChoosing () {
const chosenWorker = workers[nextWorkerIndex]
nextWorkerIndex =
function roundRobinTernaryWithPreChoosing () {
const chosenWorker = workers[nextWorkerIndex]
nextWorkerIndex =
@@
-30,6
+42,9
@@
function roundRobinTernaryWithPreChoosing () {
return chosenWorker
}
return chosenWorker
}
+/**
+ *
+ */
function roundRobinIncrementModulo () {
const chosenWorker = workers[nextWorkerIndex]
nextWorkerIndex++
function roundRobinIncrementModulo () {
const chosenWorker = workers[nextWorkerIndex]
nextWorkerIndex++
@@
-37,29
+52,23
@@
function roundRobinIncrementModulo () {
return chosenWorker
}
return chosenWorker
}
-new Benchmark.Suite('Round robin tasks distribution')
-
.add
('Ternary off by one', () => {
+group('Round robin tasks distribution', () => {
+
bench
('Ternary off by one', () => {
nextWorkerIndex = 0
roundRobinTernaryOffByOne()
})
nextWorkerIndex = 0
roundRobinTernaryOffByOne()
})
-
.add
('Ternary with negation', () => {
+
bench
('Ternary with negation', () => {
nextWorkerIndex = 0
roundRobinTernaryWithNegation()
})
nextWorkerIndex = 0
roundRobinTernaryWithNegation()
})
-
.add
('Ternary with pre-choosing', () => {
+
bench
('Ternary with pre-choosing', () => {
nextWorkerIndex = 0
roundRobinTernaryWithPreChoosing()
})
nextWorkerIndex = 0
roundRobinTernaryWithPreChoosing()
})
-
.add
('Increment+Modulo', () => {
+
bench
('Increment+Modulo', () => {
nextWorkerIndex = 0
roundRobinIncrementModulo()
})
nextWorkerIndex = 0
roundRobinIncrementModulo()
})
- .on('cycle', event => {
- console.info(event.target.toString())
- })
- .on('complete', function () {
- console.info(
- 'Fastest is ' + LIST_FORMATTER.format(this.filter('fastest').map('name'))
- )
- })
- .run()
+})
+
+await run({ units: true })