Merge dependabot/npm_and_yarn/examples/typescript/websocket-server-pool/ws-worker_thr...
[poolifier.git] / benchmarks / versus-external-pools / dynamic-poolifier.mjs
CommitLineData
8fca9288 1import { DynamicThreadPool } from 'poolifier'
35704ec7 2import { executeAsyncFn } from './utils.mjs'
479ba9f6 3
6bd72cd0
JB
4const size = parseInt(process.env.POOL_SIZE)
5const iterations = parseInt(process.env.NUM_ITERATIONS)
be0676b3 6const data = {
9f7e7a99 7 test: 'MYBENCH',
7a6a0a96 8 taskType: process.env.TASK_TYPE,
6bd72cd0 9 taskSize: parseInt(process.env.TASK_SIZE)
be0676b3
APA
10}
11
4bb5e44d 12const dynamicThreadPool = new DynamicThreadPool(
02749105 13 Math.floor(size / 2),
79e7d368 14 size,
7daf2f56
JB
15 './workers/poolifier/function-to-bench-worker.mjs',
16 {
234c3142 17 enableTasksQueue: false
7daf2f56 18 }
be0676b3
APA
19)
20
21async function run () {
1655b92e 22 const promises = new Set()
be0676b3 23 for (let i = 0; i < iterations; i++) {
4bb5e44d 24 promises.add(dynamicThreadPool.execute(data))
be0676b3
APA
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)