refactor: cleanup benchmarking code
[poolifier.git] / benchmarks / benchmarks-utils.js
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