X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=benchmarks%2Finternal%2Fbench.mjs;h=3f467f9ea49689d642a4b9eae087416d806a9735;hb=f12182ad6dc553c7a5dfeee01bcde65c0177f671;hp=2749da428bfcda15d881b0f934d35b54f8a603f2;hpb=edd5088275648b8ae534dcd75ba23443fe947954;p=poolifier.git diff --git a/benchmarks/internal/bench.mjs b/benchmarks/internal/bench.mjs index 2749da42..3f467f9e 100644 --- a/benchmarks/internal/bench.mjs +++ b/benchmarks/internal/bench.mjs @@ -1,93 +1,101 @@ -import { add, complete, cycle, save, suite } from 'benny' +import { writeFileSync } from 'node:fs' +import { env } from 'node:process' +// eslint-disable-next-line n/no-unsupported-features/node-builtins +import { parseArgs } from 'node:util' + import { - Measurements, + availableParallelism, PoolTypes, - WorkerChoiceStrategies, - WorkerTypes, - availableParallelism + WorkerTypes } from '../../lib/index.mjs' -import { TaskFunctions } from '../benchmarks-types.mjs' -import { buildPool, runTest } from '../benchmarks-utils.mjs' +import { TaskFunctions } from '../benchmarks-types.cjs' +import { + convertTatamiNgToBmf, + runPoolifierBenchmarkTatamiNg +} 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, true]) { - if (workerChoiceStrategy === WorkerChoiceStrategies.FAIR_SHARE) { - for (const measurement of [Measurements.runTime, Measurements.elu]) { - pools.push([ - `${poolType}|${workerType}|${workerChoiceStrategy}|tasks queue:${enableTasksQueue}|measurement:${measurement}`, - buildPool(workerType, poolType, poolSize, { - workerChoiceStrategy, - workerChoiceStrategyOptions: { - measurement - }, - enableTasksQueue - }) - ]) - } - } else { - pools.push([ - `${poolType}|${workerType}|${workerChoiceStrategy}|tasks queue:${enableTasksQueue}`, - buildPool(workerType, poolType, poolSize, { - workerChoiceStrategy, - enableTasksQueue - }) - ]) - } - } - } - } -} - const taskExecutions = 1 const workerData = { - function: TaskFunctions.jsonIntegerSerialization, + function: TaskFunctions.factorial, taskSize: 1000 } -const addPools = pools => - pools.map(([name, pool]) => { - return add(name, async () => { - await runTest(pool, { - taskExecutions, - workerData - }) - }) - }) +const benchmarkReportFile = 'benchmark-report.json' +let benchmarkReport -const resultsFile = 'poolifier' -const resultsFolder = 'benchmarks/internal/results' -suite( - 'Poolifier', - ...addPools(pools), - cycle(), - complete(), - save({ - file: resultsFile, - folder: resultsFolder, - format: 'json', - details: true - }), - save({ - file: resultsFile, - folder: resultsFolder, - format: 'chart.html', - details: true - }), - save({ - file: resultsFile, - folder: resultsFolder, - format: 'table.html', - details: true - }) -) - .then(() => { - // eslint-disable-next-line n/no-process-exit - return process.exit() - }) - .catch(err => console.error(err)) +switch ( + parseArgs({ + args: process.argv, + options: { + type: { + type: 'string', + short: 't' + } + }, + strict: true, + allowPositionals: true + }).values.type +) { + case 'tatami-ng': + default: + benchmarkReport = convertTatamiNgToBmf( + await runPoolifierBenchmarkTatamiNg( + 'FixedThreadPool', + WorkerTypes.thread, + PoolTypes.fixed, + poolSize, + { + taskExecutions, + workerData + } + ) + ) + benchmarkReport = { + ...benchmarkReport, + ...convertTatamiNgToBmf( + await runPoolifierBenchmarkTatamiNg( + 'DynamicThreadPool', + WorkerTypes.thread, + PoolTypes.dynamic, + poolSize, + { + taskExecutions, + workerData + } + ) + ) + } + benchmarkReport = { + ...benchmarkReport, + ...convertTatamiNgToBmf( + await runPoolifierBenchmarkTatamiNg( + 'FixedClusterPool', + WorkerTypes.cluster, + PoolTypes.fixed, + poolSize, + { + taskExecutions, + workerData + } + ) + ) + } + benchmarkReport = { + ...benchmarkReport, + ...convertTatamiNgToBmf( + await runPoolifierBenchmarkTatamiNg( + 'DynamicClusterPool', + WorkerTypes.cluster, + PoolTypes.dynamic, + poolSize, + { + taskExecutions, + workerData + } + ) + ) + } + env.CI != null && + writeFileSync(benchmarkReportFile, JSON.stringify(benchmarkReport)) + break +}