]> Piment Noir Git Repositories - poolifier.git/commitdiff
fix: fix benchmark report file generation
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 2 Dec 2025 12:42:48 +0000 (13:42 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 2 Dec 2025 12:42:48 +0000 (13:42 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
benchmarks/internal/bench.mjs

index 49f434e3b282ad0ea5878c5587656331f4644c62..4478018c3c705f333d71065eb825612b709c3458 100644 (file)
@@ -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)
 }