perf: add benchmark defaults to external pools benchmark
[poolifier.git] / benchmarks / versus-external-pools / dynamic-poolifier.mjs
1 import { DynamicThreadPool } from 'poolifier'
2 import { BenchmarkDefaults, executeAsyncFn } from './utils.mjs'
3
4 const size = parseInt(process.env.POOL_SIZE) || BenchmarkDefaults.poolSize
5 const numIterations =
6 parseInt(process.env.NUM_ITERATIONS) || BenchmarkDefaults.numIterations
7 const data = {
8 test: 'MYBENCH',
9 taskType: process.env.TASK_TYPE || BenchmarkDefaults.taskType,
10 taskSize: parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize
11 }
12
13 const dynamicThreadPool = new DynamicThreadPool(
14 Math.floor(size / 2),
15 size,
16 './workers/poolifier/function-to-bench-worker.mjs',
17 {
18 enableTasksQueue: false
19 }
20 )
21
22 async function run () {
23 const promises = new Set()
24 for (let i = 0; i < numIterations; i++) {
25 promises.add(dynamicThreadPool.execute(data))
26 }
27 await Promise.all(promises)
28 // eslint-disable-next-line n/no-process-exit
29 process.exit()
30 }
31
32 await executeAsyncFn(run)