7b7361d09f18b9113984557fcdc042c01d515552
[poolifier.git] / benchmarks / versus-external-pools / dynamic-node-worker-threads-pool.mjs
1 import { DynamicPool } from 'node-worker-threads-pool'
2 import { BenchmarkDefaults, executeAsyncFn } from './utils.mjs'
3 import functionToBench from './functions/function-to-bench.js'
4
5 const size = parseInt(process.env.POOL_SIZE) || BenchmarkDefaults.poolSize
6 const numIterations =
7 parseInt(process.env.NUM_ITERATIONS) || BenchmarkDefaults.numIterations
8 const data = {
9 test: 'MYBENCH',
10 taskType: process.env.TASK_TYPE || BenchmarkDefaults.taskType,
11 taskSize: parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize
12 }
13
14 const dynamicPool = new DynamicPool(size)
15
16 async function run () {
17 const promises = new Set()
18 for (let i = 0; i < numIterations; i++) {
19 promises.add(
20 dynamicPool.exec({
21 task: functionToBench,
22 param: data,
23 timeout: 60000 // this is the same as poolifier default
24 })
25 )
26 }
27 await Promise.all(promises)
28 // eslint-disable-next-line n/no-process-exit
29 process.exit()
30 }
31
32 await executeAsyncFn(run)