perf: add benchmark defaults to external pools benchmark
[poolifier.git] / benchmarks / versus-external-pools / fixed-tinypool.mjs
1 import Tinypool from 'tinypool'
2 import { BenchmarkDefaults, executeAsyncFn } from './utils.mjs'
3
4 const size = parseInt(process.env.POOL_SIZE) || BenchmarkDefaults.poolSize
5 const numIterations =
6 parseInt(process.env.NUM_ITERATIONS) || BenchmarkDefaults.numIterations
7 const data = {
8 test: 'MYBENCH',
9 taskType: process.env.TASK_TYPE || BenchmarkDefaults.taskType,
10 taskSize: parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize
11 }
12
13 const tinypool = new Tinypool({
14 filename: './workers/tinypool/function-to-bench-worker.mjs',
15 minThreads: size,
16 maxThreads: size,
17 idleTimeout: 60000 // this is the same as poolifier default
18 })
19
20 async function run () {
21 const promises = new Set()
22 for (let i = 0; i < numIterations; i++) {
23 promises.add(tinypool.run(data))
24 }
25 await Promise.all(promises)
26 // eslint-disable-next-line n/no-process-exit
27 process.exit()
28 }
29
30 await executeAsyncFn(run)