perf: add benchmark defaults to external pools benchmark
[poolifier.git] / benchmarks / versus-external-pools / static-node-worker-threads-pool.mjs
CommitLineData
8fca9288 1import { StaticPool } from 'node-worker-threads-pool'
91a40166 2import { BenchmarkDefaults, executeAsyncFn } from './utils.mjs'
bea2d6e3 3import functionToBench from './functions/function-to-bench.js'
479ba9f6 4
91a40166
JB
5const size = parseInt(process.env.POOL_SIZE) || BenchmarkDefaults.poolSize
6const numIterations =
7 parseInt(process.env.NUM_ITERATIONS) || BenchmarkDefaults.numIterations
be0676b3 8const data = {
9f7e7a99 9 test: 'MYBENCH',
91a40166
JB
10 taskType: process.env.TASK_TYPE || BenchmarkDefaults.taskType,
11 taskSize: parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize
be0676b3
APA
12}
13
4bb5e44d 14const staticPool = new StaticPool({
7a6a0a96 15 size,
be0676b3
APA
16 task: functionToBench
17})
18
19async function run () {
1655b92e 20 const promises = new Set()
91a40166 21 for (let i = 0; i < numIterations; i++) {
4bb5e44d 22 promises.add(staticPool.exec(data))
be0676b3
APA
23 }
24 await Promise.all(promises)
2f8c5b5c 25 // eslint-disable-next-line n/no-process-exit
be0676b3
APA
26 process.exit()
27}
28
479ba9f6 29await executeAsyncFn(run)