perf: fix continuous benchmarking
[poolifier.git] / benchmarks / internal / bench.mjs
index da0c023d611cf47904148f9c3541d05a4d400b99..0e3ee055a474e5a439c5a9b1fcde3de218271193 100644 (file)
@@ -1,4 +1,5 @@
-import { exit } from 'node:process'
+import { writeFileSync } from 'node:fs'
+import { env, exit } from 'node:process'
 // eslint-disable-next-line n/no-unsupported-features/node-builtins
 import { parseArgs } from 'node:util'
 
@@ -9,7 +10,7 @@ import {
 } from '../../lib/index.mjs'
 import { TaskFunctions } from '../benchmarks-types.cjs'
 import {
-  runPoolifierBenchmarkBenchmarkJsSuite,
+  convertTatamiNgToBmf,
   runPoolifierBenchmarkTatamiNg
 } from '../benchmarks-utils.mjs'
 
@@ -19,6 +20,8 @@ const workerData = {
   function: TaskFunctions.factorial,
   taskSize: 1000
 }
+const benchmarkReportFile = 'benchmark-report.json'
+let benchmarkReport
 
 switch (
   parseArgs({
@@ -34,89 +37,66 @@ switch (
   }).values.type
 ) {
   case 'tatami-ng':
-    await runPoolifierBenchmarkTatamiNg(
-      'FixedThreadPool',
-      WorkerTypes.thread,
-      PoolTypes.fixed,
-      poolSize,
-      {
-        taskExecutions,
-        workerData
-      }
-    )
-    await runPoolifierBenchmarkTatamiNg(
-      'DynamicThreadPool',
-      WorkerTypes.thread,
-      PoolTypes.dynamic,
-      poolSize,
-      {
-        taskExecutions,
-        workerData
-      }
-    )
-    await runPoolifierBenchmarkTatamiNg(
-      'FixedClusterPool',
-      WorkerTypes.cluster,
-      PoolTypes.fixed,
-      poolSize,
-      {
-        taskExecutions,
-        workerData
-      }
-    )
-    await runPoolifierBenchmarkTatamiNg(
-      'DynamicClusterPool',
-      WorkerTypes.cluster,
-      PoolTypes.dynamic,
-      poolSize,
-      {
-        taskExecutions,
-        workerData
-      }
-    )
-    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
-      }
+    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
 }