From 472bf1f5aa50f29e44d194437964127f3bd0e3f4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 14 Feb 2021 14:12:15 +0100 Subject: [PATCH] Benchmark: Ensure choice algos does not init with off-by-one (#151) Co-authored-by: Shinigami92 --- benchmarks/choose-worker.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/benchmarks/choose-worker.js b/benchmarks/choose-worker.js index 38e6fc7c..fe98eff1 100644 --- a/benchmarks/choose-worker.js +++ b/benchmarks/choose-worker.js @@ -17,7 +17,15 @@ function chooseWorkerTernary () { return workers[nextWorkerIndex] } -function chooseWorkerIncrementModuloWithPreChoosing () { +function chooseWorkerTernaryWithNegation () { + nextWorkerIndex = + !nextWorkerIndex || workers.length - 1 === nextWorkerIndex + ? 0 + : nextWorkerIndex + 1 + return workers[nextWorkerIndex] +} + +function chooseWorkerTernaryWithPreChoosing () { const chosenWorker = workers[nextWorkerIndex] nextWorkerIndex = workers.length - 1 === nextWorkerIndex ? 0 : nextWorkerIndex + 1 @@ -36,9 +44,13 @@ suite nextWorkerIndex = 0 chooseWorkerTernary() }) - .add('Increment+Modulo with PreChoosing', function () { + .add('Ternary with negation', function () { + nextWorkerIndex = 0 + chooseWorkerTernaryWithNegation() + }) + .add('Ternary with PreChoosing', function () { nextWorkerIndex = 0 - chooseWorkerIncrementModuloWithPreChoosing() + chooseWorkerTernaryWithPreChoosing() }) .add('Increment+Modulo', function () { nextWorkerIndex = 0 -- 2.34.1