From e09bdfac2d4985187a145330c5bcc656d5db7c95 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 2 Dec 2025 13:42:48 +0100 Subject: [PATCH] fix: fix benchmark report file generation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- benchmarks/internal/bench.mjs | 136 ++++++++++++++++++---------------- 1 file changed, 74 insertions(+), 62 deletions(-) diff --git a/benchmarks/internal/bench.mjs b/benchmarks/internal/bench.mjs index 49f434e3b..4478018c3 100644 --- a/benchmarks/internal/bench.mjs +++ b/benchmarks/internal/bench.mjs @@ -1,5 +1,5 @@ import { writeFileSync } from 'node:fs' -import { env } from 'node:process' +import { env, exit } from 'node:process' import { parseArgs } from 'node:util' import { @@ -17,74 +17,86 @@ const workerData = { taskSize: 1000, } const benchmarkReportFile = 'benchmark-report.json' -let benchmarkReport -switch ( - parseArgs({ - allowPositionals: true, - args: process.argv, - options: { - type: { - short: 't', - type: 'string', +const runBenchmark = async () => { + let benchmarkReport = {} + + switch ( + parseArgs({ + allowPositionals: true, + args: process.argv, + options: { + type: { + short: 't', + type: 'string', + }, }, - }, - strict: true, - }).values.type -) { - case 'tinybench': - default: - benchmarkReport = await runPoolifierBenchmarkTinyBench( - 'FixedThreadPool', - WorkerTypes.thread, - PoolTypes.fixed, - poolSize, - { - taskExecutions, - workerData, - } - ) - benchmarkReport = { - ...benchmarkReport, - ...(await runPoolifierBenchmarkTinyBench( - 'DynamicThreadPool', + strict: true, + }).values.type + ) { + case 'tinybench': + default: + benchmarkReport = await runPoolifierBenchmarkTinyBench( + 'FixedThreadPool', WorkerTypes.thread, - PoolTypes.dynamic, - poolSize, - { - taskExecutions, - workerData, - } - )), - } - benchmarkReport = { - ...benchmarkReport, - ...(await runPoolifierBenchmarkTinyBench( - 'FixedClusterPool', - WorkerTypes.cluster, PoolTypes.fixed, poolSize, { taskExecutions, workerData, } - )), - } - benchmarkReport = { - ...benchmarkReport, - ...(await runPoolifierBenchmarkTinyBench( - 'DynamicClusterPool', - WorkerTypes.cluster, - PoolTypes.dynamic, - poolSize, - { - taskExecutions, - workerData, - } - )), - } - // eslint-disable-next-line @typescript-eslint/no-unused-expressions - env.CI != null && - writeFileSync(benchmarkReportFile, JSON.stringify(benchmarkReport)) - break + ) + benchmarkReport = { + ...benchmarkReport, + ...(await runPoolifierBenchmarkTinyBench( + 'DynamicThreadPool', + WorkerTypes.thread, + PoolTypes.dynamic, + poolSize, + { + taskExecutions, + workerData, + } + )), + } + benchmarkReport = { + ...benchmarkReport, + ...(await runPoolifierBenchmarkTinyBench( + 'FixedClusterPool', + WorkerTypes.cluster, + PoolTypes.fixed, + poolSize, + { + taskExecutions, + workerData, + } + )), + } + benchmarkReport = { + ...benchmarkReport, + ...(await runPoolifierBenchmarkTinyBench( + 'DynamicClusterPool', + WorkerTypes.cluster, + PoolTypes.dynamic, + poolSize, + { + taskExecutions, + workerData, + } + )), + } + break + } + + return benchmarkReport +} + +try { + const benchmarkReport = await runBenchmark() + if (env.CI != null) { + writeFileSync(benchmarkReportFile, JSON.stringify(benchmarkReport)) + } +} catch (error) { + console.error(error) + exit(1) } -- 2.43.0