X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=benchmarks%2Finternal%2Fbench.mjs;h=adff36153241f7843f702547237280a509bb7326;hb=5aa31a743fde300612ae89a242b809ae7db083ed;hp=891ff9eca7118d5bb530e43d23315dcbdfa7c59f;hpb=440042a64e5beb9e3e97f513198f4bd2d4a896a6;p=poolifier.git diff --git a/benchmarks/internal/bench.mjs b/benchmarks/internal/bench.mjs index 891ff9ec..adff3615 100644 --- a/benchmarks/internal/bench.mjs +++ b/benchmarks/internal/bench.mjs @@ -1,67 +1,62 @@ -import assert from 'node:assert' -import Benchmark from 'benchmark' import { PoolTypes, - WorkerChoiceStrategies, WorkerTypes, availableParallelism } from '../../lib/index.mjs' -import { TaskFunctions } from '../benchmarks-types.mjs' -import { - LIST_FORMATTER, - buildPoolifierPool, - getPoolImplementationName, - runPoolifierTest -} from '../benchmarks-utils.mjs' +import { TaskFunctions } from '../benchmarks-types.js' +import { runPoolifierPoolBenchmark } from '../benchmarks-utils.js' const poolSize = availableParallelism() -const fixedThreadPool = buildPoolifierPool( - WorkerTypes.thread, - PoolTypes.fixed, - poolSize -) - const taskExecutions = 1 const workerData = { function: TaskFunctions.jsonIntegerSerialization, taskSize: 1000 } -const poolifierSuite = new Benchmark.Suite('Poolifier') +// FixedThreadPool +await runPoolifierPoolBenchmark( + 'FixedThreadPool', + WorkerTypes.thread, + PoolTypes.fixed, + poolSize, + { + taskExecutions, + workerData + } +) + +// DynamicThreadPool +await runPoolifierPoolBenchmark( + 'DynamicThreadPool', + WorkerTypes.thread, + PoolTypes.dynamic, + poolSize, + { + taskExecutions, + workerData + } +) -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 - }) - } - ) - } +// FixedClusterPool +await runPoolifierPoolBenchmark( + 'FixedClusterPool', + WorkerTypes.cluster, + PoolTypes.fixed, + poolSize, + { + taskExecutions, + workerData } -} +) -poolifierSuite - .on('cycle', event => { - console.info(event.target.toString()) - }) - .on('complete', async function () { - console.info( - 'Fastest is ' + LIST_FORMATTER.format(this.filter('fastest').map('name')) - ) - await fixedThreadPool.destroy() - }) - .run({ async: true }) +// DynamicClusterPool +await runPoolifierPoolBenchmark( + 'DynamicClusterPool', + WorkerTypes.cluster, + PoolTypes.dynamic, + poolSize, + { + taskExecutions, + workerData + } +)