X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=benchmarks%2Fworker-selection%2Fround-robin.mjs;h=64ea78da719cf0ef0607bfa4f8e27cb0e4977388;hb=3b594fe1b0f89d6665da2eb2ebdc14eb7628fe70;hp=302cd2c6dffa5e5fa1a76c42f6056327a857c895;hpb=229e9e73566ed1960ba5be0534fb3aa2eeb115eb;p=poolifier.git diff --git a/benchmarks/worker-selection/round-robin.mjs b/benchmarks/worker-selection/round-robin.mjs index 302cd2c6..64ea78da 100644 --- a/benchmarks/worker-selection/round-robin.mjs +++ b/benchmarks/worker-selection/round-robin.mjs @@ -1,6 +1,10 @@ -import Benchmark from 'benchmark' -import { LIST_FORMATTER } from '../benchmarks-utils.js' +import { bench, group, run } from 'tatami-ng' +/** + * + * @param numberOfWorkers + * @returns + */ function generateWorkersArray (numberOfWorkers) { return [...Array(numberOfWorkers).keys()] } @@ -9,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 @@ -23,6 +33,9 @@ function roundRobinTernaryWithNegation () { return workers[nextWorkerIndex] } +/** + * @returns + */ function roundRobinTernaryWithPreChoosing () { const chosenWorker = workers[nextWorkerIndex] nextWorkerIndex = @@ -30,6 +43,9 @@ function roundRobinTernaryWithPreChoosing () { return chosenWorker } +/** + * @returns + */ function roundRobinIncrementModulo () { const chosenWorker = workers[nextWorkerIndex] nextWorkerIndex++ @@ -37,29 +53,23 @@ function roundRobinIncrementModulo () { 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() }) - .add('Ternary with negation', () => { + bench('Ternary with negation', () => { nextWorkerIndex = 0 roundRobinTernaryWithNegation() }) - .add('Ternary with pre-choosing', () => { + bench('Ternary with pre-choosing', () => { nextWorkerIndex = 0 roundRobinTernaryWithPreChoosing() }) - .add('Increment+Modulo', () => { + bench('Increment+Modulo', () => { 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 })