perf: add benchmark defaults to external pools benchmark
[poolifier.git] / benchmarks / versus-external-pools / fixed-nanothreads.mjs
CommitLineData
76e2e978 1import { ThreadPool } from 'nanothreads'
91a40166 2import { BenchmarkDefaults, executeAsyncFn } from './utils.mjs'
76e2e978 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
76e2e978
JB
8const data = {
9 test: 'MYBENCH',
91a40166
JB
10 taskType: process.env.TASK_TYPE || BenchmarkDefaults.taskType,
11 taskSize: parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize
76e2e978
JB
12}
13
14const threadPool = new ThreadPool({
15 task: functionToBench,
16 count: size
17})
18
19async function run () {
20 const promises = new Set()
91a40166 21 for (let i = 0; i < numIterations; i++) {
76e2e978
JB
22 promises.add(threadPool.exec(data))
23 }
24 await Promise.all(promises)
25 // eslint-disable-next-line n/no-process-exit
26 process.exit()
27}
28
479ba9f6 29await executeAsyncFn(run)