From d9d8c14e8c3bf643e42c84b4cc5144da899dc744 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 23 Jul 2023 21:01:23 +0200 Subject: [PATCH] perf: add measurement coverage to benchmark MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- benchmarks/benchmarks-types.mjs | 6 +--- benchmarks/benchmarks-utils.mjs | 6 ++-- benchmarks/internal/bench.mjs | 54 ++++++++++++++++++--------------- 3 files changed, 34 insertions(+), 32 deletions(-) diff --git a/benchmarks/benchmarks-types.mjs b/benchmarks/benchmarks-types.mjs index dcffd136..3287cc3c 100644 --- a/benchmarks/benchmarks-types.mjs +++ b/benchmarks/benchmarks-types.mjs @@ -1,10 +1,6 @@ -import { PoolTypes, WorkerTypes } from '../lib/index.mjs' - -const WorkerFunctions = { +export const WorkerFunctions = { jsonIntegerSerialization: 'jsonIntegerSerialization', fibonacci: 'fibonacci', factorial: 'factorial', readWriteFiles: 'readWriteFiles' } - -export { PoolTypes, WorkerFunctions, WorkerTypes } diff --git a/benchmarks/benchmarks-utils.mjs b/benchmarks/benchmarks-utils.mjs index 8819c592..48c8fc3e 100644 --- a/benchmarks/benchmarks-utils.mjs +++ b/benchmarks/benchmarks-utils.mjs @@ -4,9 +4,11 @@ import { DynamicClusterPool, DynamicThreadPool, FixedClusterPool, - FixedThreadPool + FixedThreadPool, + PoolTypes, + WorkerTypes } from '../lib/index.mjs' -import { PoolTypes, WorkerFunctions, WorkerTypes } from './benchmarks-types.mjs' +import { WorkerFunctions } from './benchmarks-types.mjs' export const runTest = async (pool, { taskExecutions, workerData }) => { return new Promise((resolve, reject) => { diff --git a/benchmarks/internal/bench.mjs b/benchmarks/internal/bench.mjs index 41c035e6..48f30f66 100644 --- a/benchmarks/internal/bench.mjs +++ b/benchmarks/internal/bench.mjs @@ -1,13 +1,12 @@ import { add, complete, cycle, save, suite } from 'benny' import { + Measurements, + PoolTypes, WorkerChoiceStrategies, + WorkerTypes, availableParallelism } from '../../lib/index.mjs' -import { - PoolTypes, - WorkerFunctions, - WorkerTypes -} from '../benchmarks-types.mjs' +import { WorkerFunctions } from '../benchmarks-types.mjs' import { buildPool, runTest } from '../benchmarks-utils.mjs' const poolSize = availableParallelism() @@ -18,26 +17,31 @@ for (const poolType of Object.values(PoolTypes)) { continue } for (const workerChoiceStrategy of Object.values(WorkerChoiceStrategies)) { - for (const tasksQueue of [false, true]) { - const pool = buildPool( - workerType, - poolType, - poolSize, - tasksQueue - ? { - ...{ - workerChoiceStrategy - }, - ...{ enableTasksQueue: true } - } - : { - workerChoiceStrategy - } - ) - pools.push([ - `${poolType}|${workerType}|${workerChoiceStrategy}|tasks queue:${tasksQueue}`, - pool - ]) + for (const enableTasksQueue of [false, true]) { + if (workerChoiceStrategy === WorkerChoiceStrategies.FAIR_SHARE) { + for (const measurement of [Measurements.runTime, Measurements.elu]) { + const pool = buildPool(workerType, poolType, poolSize, { + workerChoiceStrategy, + workerChoiceStrategyOptions: { + measurement + }, + enableTasksQueue + }) + pools.push([ + `${poolType}|${workerType}|${workerChoiceStrategy}|tasks queue:${enableTasksQueue}|measurement:${measurement}`, + pool + ]) + } + } else { + const pool = buildPool(workerType, poolType, poolSize, { + workerChoiceStrategy, + enableTasksQueue + }) + pools.push([ + `${poolType}|${workerType}|${workerChoiceStrategy}|tasks queue:${enableTasksQueue}`, + pool + ]) + } } } } -- 2.34.1