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