refactor: cleanup benchmarking code
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 20 Oct 2023 17:18:20 +0000 (19:18 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 20 Oct 2023 17:18:20 +0000 (19:18 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
CHANGELOG.md
benchmarks/README.md
benchmarks/benchmarks-utils.js
benchmarks/internal/bench.mjs

index 054e24882972ec9765fc8120b4438677344caf73..4986348ddcae489d596938651e396e7a4ef6d861 100644 (file)
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Changed
 
+- Switch to Bencher for benchmarking: [https://bencher.dev/perf/poolifier](https://bencher.dev/perf/poolifier).
 - Use builtin retry mechanism in worker choice strategies instead of custom one.
 
 ## [3.0.3] - 2023-10-19
index 2008e9f0e24f38c7068897a1ee6844a26039695d..ca2b0667e86e35f34fd8d4f6c70f4456451bbe62 100644 (file)
@@ -43,4 +43,4 @@ Read the [README.md](https://github.com/poolifier/benchmark#readme) to know how
 
 To run the internal benchmark, you just need to navigate to the root of poolifier cloned repository and run `pnpm benchmark`.
 
-### [Results](https://poolifier.github.io/benchmark-results/dev/bench)
+### [Results](https://bencher.dev/perf/poolifier)
index 48311a3f04b773c0d6f540eaf659b2b00f3e08d7..678b41d7634e56254c3cfb660738aea2cf8ee20d 100644 (file)
@@ -76,12 +76,15 @@ const runPoolifierPool = async (pool, { taskExecutions, workerData }) => {
 
 const runPoolifierPoolBenchmark = async (
   name,
-  pool,
+  workerType,
+  poolType,
+  poolSize,
   { taskExecutions, workerData }
 ) => {
+  const pool = buildPoolifierPool(workerType, poolType, poolSize)
+  const suite = new Benchmark.Suite(name)
   return await new Promise((resolve, reject) => {
     try {
-      const suite = new Benchmark.Suite(name)
       for (const workerChoiceStrategy of Object.values(
         WorkerChoiceStrategies
       )) {
@@ -151,12 +154,16 @@ const runPoolifierPoolBenchmark = async (
               LIST_FORMATTER.format(this.filter('fastest').map('name'))
           )
           await pool.destroy()
-          pool = undefined
           resolve()
         })
         .run({ async: true })
     } catch (error) {
-      reject(error)
+      pool
+        .destroy()
+        .then(() => {
+          return reject(error)
+        })
+        .catch(() => {})
     }
   })
 }
@@ -249,7 +256,6 @@ const executeTaskFunction = data => {
 
 module.exports = {
   LIST_FORMATTER,
-  buildPoolifierPool,
   executeTaskFunction,
   generateRandomInteger,
   runPoolifierPoolBenchmark
index 7ef61bc6cba31225a4d8732b721422494deeb4d3..368cf29c949f487b3223b5dd90c74beedcd359d1 100644 (file)
@@ -4,10 +4,7 @@ import {
   availableParallelism
 } from '../../lib/index.mjs'
 import { TaskFunctions } from '../benchmarks-types.js'
-import {
-  buildPoolifierPool,
-  runPoolifierPoolBenchmark
-} from '../benchmarks-utils.js'
+import { runPoolifierPoolBenchmark } from '../benchmarks-utils.js'
 
 const poolSize = availableParallelism()
 const taskExecutions = 1
@@ -19,7 +16,9 @@ const workerData = {
 // FixedThreadPool
 await runPoolifierPoolBenchmark(
   'Poolifier FixedThreadPool',
-  buildPoolifierPool(WorkerTypes.thread, PoolTypes.fixed, poolSize),
+  WorkerTypes.thread,
+  PoolTypes.fixed,
+  poolSize,
   {
     taskExecutions,
     workerData
@@ -29,7 +28,9 @@ await runPoolifierPoolBenchmark(
 // DynamicThreadPool
 await runPoolifierPoolBenchmark(
   'Poolifier DynamicThreadPool',
-  buildPoolifierPool(WorkerTypes.thread, PoolTypes.dynamic, poolSize),
+  WorkerTypes.thread,
+  PoolTypes.dynamic,
+  poolSize,
   {
     taskExecutions,
     workerData
@@ -39,7 +40,9 @@ await runPoolifierPoolBenchmark(
 // FixedClusterPool
 await runPoolifierPoolBenchmark(
   'Poolifier FixedClusterPool',
-  buildPoolifierPool(WorkerTypes.cluster, PoolTypes.fixed, poolSize),
+  WorkerTypes.cluster,
+  PoolTypes.fixed,
+  poolSize,
   {
     taskExecutions,
     workerData
@@ -49,7 +52,9 @@ await runPoolifierPoolBenchmark(
 // DynamicClusterPool
 await runPoolifierPoolBenchmark(
   'Poolifier DynamicClusterPool',
-  buildPoolifierPool(WorkerTypes.cluster, PoolTypes.dynamic, poolSize),
+  WorkerTypes.cluster,
+  PoolTypes.dynamic,
+  poolSize,
   {
     taskExecutions,
     workerData