perf: add benchmark defaults to external pools benchmark
[poolifier.git] / benchmarks / versus-external-pools / fixed-nanothreads.mjs
index d18f71b51d82e6c92a56c017a989c2487016864c..3b497af5ed9306223841ffe6b4ceb31a9e07f29e 100644 (file)
@@ -1,13 +1,14 @@
 import { ThreadPool } from 'nanothreads'
-import { executeAsyncFn } from './utils.mjs'
+import { BenchmarkDefaults, executeAsyncFn } from './utils.mjs'
 import functionToBench from './functions/function-to-bench.js'
 
-const size = parseInt(process.env.POOL_SIZE)
-const iterations = parseInt(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE) || BenchmarkDefaults.poolSize
+const numIterations =
+  parseInt(process.env.NUM_ITERATIONS) || BenchmarkDefaults.numIterations
 const data = {
   test: 'MYBENCH',
-  taskType: process.env.TASK_TYPE,
-  taskSize: parseInt(process.env.TASK_SIZE)
+  taskType: process.env.TASK_TYPE || BenchmarkDefaults.taskType,
+  taskSize: parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize
 }
 
 const threadPool = new ThreadPool({
@@ -17,7 +18,7 @@ const threadPool = new ThreadPool({
 
 async function run () {
   const promises = new Set()
-  for (let i = 0; i < iterations; i++) {
+  for (let i = 0; i < numIterations; i++) {
     promises.add(threadPool.exec(data))
   }
   await Promise.all(promises)