X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=benchmarks%2Finternal%2Fbench.mjs;h=88868af7c43c1c3e4e5cce039f2fac71a6b99946;hb=46268b76dc942050598548d8780b07ec008dde4d;hp=891ff9eca7118d5bb530e43d23315dcbdfa7c59f;hpb=d293923f776bb52bd76b23a2794e1b23832502a1;p=poolifier.git diff --git a/benchmarks/internal/bench.mjs b/benchmarks/internal/bench.mjs index 891ff9ec..88868af7 100644 --- a/benchmarks/internal/bench.mjs +++ b/benchmarks/internal/bench.mjs @@ -1,67 +1,65 @@ -import assert from 'node:assert' -import Benchmark from 'benchmark' +import { exit } from 'node:process' 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.cjs' +import { runPoolifierPoolBenchmark } from '../benchmarks-utils.cjs' 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 + } +) -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 - }) - } - ) - } +// DynamicThreadPool +await runPoolifierPoolBenchmark( + 'DynamicThreadPool', + WorkerTypes.thread, + PoolTypes.dynamic, + poolSize, + { + taskExecutions, + workerData } -} +) + +// FixedClusterPool +await runPoolifierPoolBenchmark( + 'FixedClusterPool', + WorkerTypes.cluster, + PoolTypes.fixed, + poolSize, + { + taskExecutions, + workerData + } +) + +// DynamicClusterPool +await runPoolifierPoolBenchmark( + 'DynamicClusterPool', + WorkerTypes.cluster, + PoolTypes.dynamic, + 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 }) +exit()