X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=benchmarks%2Finternal%2Fbench.mjs;h=564a4de14621bf6bd096e7fc940753f8eb6ee0d9;hb=9f37a36c31a30e0fe60696afddacd89490953e93;hp=88868af7c43c1c3e4e5cce039f2fac71a6b99946;hpb=d35e571704515a8b729d3455e4784054f07c368f;p=poolifier.git diff --git a/benchmarks/internal/bench.mjs b/benchmarks/internal/bench.mjs index 88868af7..564a4de1 100644 --- a/benchmarks/internal/bench.mjs +++ b/benchmarks/internal/bench.mjs @@ -1,65 +1,133 @@ import { exit } from 'node:process' +import { parseArgs } from 'node:util' + +import { run } from 'mitata' + import { + availableParallelism, PoolTypes, - WorkerTypes, - availableParallelism + WorkerTypes } from '../../lib/index.mjs' import { TaskFunctions } from '../benchmarks-types.cjs' -import { runPoolifierPoolBenchmark } from '../benchmarks-utils.cjs' +import { + buildPoolifierBenchmarkMitata, + runPoolifierBenchmarkBenchmarkJsSuite +} from '../benchmarks-utils.mjs' const poolSize = availableParallelism() const taskExecutions = 1 const workerData = { - function: TaskFunctions.jsonIntegerSerialization, - taskSize: 1000 + function: TaskFunctions.factorial, + taskSize: 50000 } -// FixedThreadPool -await runPoolifierPoolBenchmark( - 'FixedThreadPool', - WorkerTypes.thread, - PoolTypes.fixed, - poolSize, - { - 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 - } -) +let fixedThreadPool +let dynamicThreadPool +let fixedClusterPool +let dynamicClusterPool +switch ( + parseArgs({ + args: process.argv, + options: { + type: { + type: 'string', + short: 't' + } + }, + strict: true, + allowPositionals: true + }).values.type +) { + case 'mitata': + fixedThreadPool = buildPoolifierBenchmarkMitata( + 'FixedThreadPool', + WorkerTypes.thread, + PoolTypes.fixed, + poolSize, + { + taskExecutions, + workerData + } + ) + dynamicThreadPool = buildPoolifierBenchmarkMitata( + 'DynamicThreadPool', + WorkerTypes.thread, + PoolTypes.dynamic, + poolSize, + { + taskExecutions, + workerData + } + ) + fixedClusterPool = buildPoolifierBenchmarkMitata( + 'FixedClusterPool', + WorkerTypes.cluster, + PoolTypes.fixed, + poolSize, + { + taskExecutions, + workerData + } + ) + dynamicClusterPool = buildPoolifierBenchmarkMitata( + 'DynamicClusterPool', + WorkerTypes.cluster, + PoolTypes.dynamic, + poolSize, + { + taskExecutions, + workerData + } + ) + await run() + await fixedThreadPool.destroy() + await dynamicThreadPool.destroy() + await fixedClusterPool.destroy() + await dynamicClusterPool.destroy() + break + case 'benchmark.js': + default: + await runPoolifierBenchmarkBenchmarkJsSuite( + 'FixedThreadPool', + WorkerTypes.thread, + PoolTypes.fixed, + poolSize, + { + taskExecutions, + workerData + } + ) + await runPoolifierBenchmarkBenchmarkJsSuite( + 'DynamicThreadPool', + WorkerTypes.thread, + PoolTypes.dynamic, + poolSize, + { + taskExecutions, + workerData + } + ) + await runPoolifierBenchmarkBenchmarkJsSuite( + 'FixedClusterPool', + WorkerTypes.cluster, + PoolTypes.fixed, + poolSize, + { + taskExecutions, + workerData + } + ) + await runPoolifierBenchmarkBenchmarkJsSuite( + 'DynamicClusterPool', + WorkerTypes.cluster, + PoolTypes.dynamic, + poolSize, + { + taskExecutions, + workerData + } + ) + break +} exit()