fix: make benchmark vs. external pools self-contained
[poolifier.git] / benchmarks / versus-external-pools / static-node-worker-threads-pool.mjs
CommitLineData
8fca9288 1import { StaticPool } 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 staticPool = new StaticPool({
7a6a0a96 14 size,
be0676b3
APA
15 task: functionToBench
16})
17
18async function run () {
1655b92e 19 const promises = new Set()
be0676b3 20 for (let i = 0; i < iterations; i++) {
4bb5e44d 21 promises.add(staticPool.exec(data))
be0676b3
APA
22 }
23 await Promise.all(promises)
2f8c5b5c 24 // eslint-disable-next-line n/no-process-exit
be0676b3
APA
25 process.exit()
26}
27
479ba9f6 28await executeAsyncFn(run)