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