X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=benchmarks%2Finternal%2Fbench.mjs;h=891ff9eca7118d5bb530e43d23315dcbdfa7c59f;hb=4e1212db1d198963828820471bde6902277d0388;hp=23ab0625807e349b89f6fabd55be766e45f9fff5;hpb=f1c674cd6caabfbe46bc99d412611b4a91727c5f;p=poolifier.git diff --git a/benchmarks/internal/bench.mjs b/benchmarks/internal/bench.mjs index 23ab0625..891ff9ec 100644 --- a/benchmarks/internal/bench.mjs +++ b/benchmarks/internal/bench.mjs @@ -1,6 +1,6 @@ +import assert from 'node:assert' import Benchmark from 'benchmark' import { - Measurements, PoolTypes, WorkerChoiceStrategies, WorkerTypes, @@ -10,70 +10,58 @@ import { TaskFunctions } from '../benchmarks-types.mjs' import { LIST_FORMATTER, buildPoolifierPool, + getPoolImplementationName, runPoolifierTest } from '../benchmarks-utils.mjs' const poolSize = availableParallelism() -const pools = [] -for (const poolType of Object.values(PoolTypes)) { - for (const workerType of Object.values(WorkerTypes)) { - if (workerType === WorkerTypes.cluster) { - continue - } - for (const workerChoiceStrategy of Object.values(WorkerChoiceStrategies)) { - for (const enableTasksQueue of [false]) { - if (workerChoiceStrategy === WorkerChoiceStrategies.FAIR_SHARE) { - for (const measurement of [Measurements.runTime, Measurements.elu]) { - pools.push([ - `${poolType}|${workerType}|${workerChoiceStrategy}|tasks queue:${enableTasksQueue}|measurement:${measurement}`, - buildPoolifierPool(workerType, poolType, poolSize, { - workerChoiceStrategy, - workerChoiceStrategyOptions: { - measurement - }, - enableTasksQueue - }) - ]) - } - } else { - pools.push([ - `${poolType}|${workerType}|${workerChoiceStrategy}|tasks queue:${enableTasksQueue}`, - buildPoolifierPool(workerType, poolType, poolSize, { - workerChoiceStrategy, - enableTasksQueue - }) - ]) - } - } - } - } -} +const fixedThreadPool = buildPoolifierPool( + WorkerTypes.thread, + PoolTypes.fixed, + poolSize +) const taskExecutions = 1 const workerData = { function: TaskFunctions.jsonIntegerSerialization, - taskSize: 100 + taskSize: 1000 } -const suite = new Benchmark.Suite('Poolifier') -for (const [name, pool] of pools) { - suite.add(name, async () => { - await runPoolifierTest(pool, { - taskExecutions, - workerData - }) - }) +const poolifierSuite = new Benchmark.Suite('Poolifier') + +for (const pool of [fixedThreadPool]) { + for (const workerChoiceStrategy of Object.values(WorkerChoiceStrategies)) { + for (const enableTasksQueue of [false, true]) { + poolifierSuite.add( + `${getPoolImplementationName(pool)}|${workerChoiceStrategy}|${ + enableTasksQueue ? 'with' : 'without' + } tasks queue`, + async () => { + pool.setWorkerChoiceStrategy(workerChoiceStrategy) + pool.enableTasksQueue(enableTasksQueue) + assert.strictEqual( + pool.opts.workerChoiceStrategy, + workerChoiceStrategy + ) + assert.strictEqual(pool.opts.enableTasksQueue, enableTasksQueue) + await runPoolifierTest(pool, { + taskExecutions, + workerData + }) + } + ) + } + } } -suite +poolifierSuite .on('cycle', event => { console.info(event.target.toString()) }) - .on('complete', function () { + .on('complete', async function () { console.info( 'Fastest is ' + LIST_FORMATTER.format(this.filter('fastest').map('name')) ) - // eslint-disable-next-line n/no-process-exit - process.exit() + await fixedThreadPool.destroy() }) - .run({ async: true, maxTime: 120 }) + .run({ async: true })