fix: make benchmark vs. external pools self-contained
[poolifier.git] / benchmarks / versus-external-pools / dynamic-node-worker-threads-pool.mjs
CommitLineData
8fca9288 1import { DynamicPool } from 'node-worker-threads-pool'
35704ec7 2import { executeAsyncFn } from './utils.mjs'
bea2d6e3 3import functionToBench from './functions/function-to-bench.js'
479ba9f6 4
6bd72cd0
JB
5const size = parseInt(process.env.POOL_SIZE)
6const iterations = parseInt(process.env.NUM_ITERATIONS)
be0676b3 7const data = {
9f7e7a99 8 test: 'MYBENCH',
7a6a0a96 9 taskType: process.env.TASK_TYPE,
6bd72cd0 10 taskSize: parseInt(process.env.TASK_SIZE)
be0676b3
APA
11}
12
4bb5e44d 13const dynamicPool = new DynamicPool(size)
be0676b3
APA
14
15async function run () {
1655b92e 16 const promises = new Set()
be0676b3 17 for (let i = 0; i < iterations; i++) {
1655b92e 18 promises.add(
4bb5e44d 19 dynamicPool.exec({
be0676b3 20 task: functionToBench,
ae55bb0e
JB
21 param: data,
22 timeout: 60000 // this is the same as poolifier default
be0676b3
APA
23 })
24 )
25 }
26 await Promise.all(promises)
2f8c5b5c 27 // eslint-disable-next-line n/no-process-exit
be0676b3
APA
28 process.exit()
29}
30
479ba9f6 31await executeAsyncFn(run)