fix: make benchmark vs. external pools self-contained
[poolifier.git] / benchmarks / versus-external-pools / fixed-nanothreads.mjs
CommitLineData
76e2e978 1import { ThreadPool } from 'nanothreads'
35704ec7 2import { executeAsyncFn } from './utils.mjs'
76e2e978 3import functionToBench from './functions/function-to-bench.js'
479ba9f6 4
76e2e978
JB
5const size = parseInt(process.env.POOL_SIZE)
6const iterations = parseInt(process.env.NUM_ITERATIONS)
7const data = {
8 test: 'MYBENCH',
9 taskType: process.env.TASK_TYPE,
10 taskSize: parseInt(process.env.TASK_SIZE)
11}
12
13const threadPool = new ThreadPool({
14 task: functionToBench,
15 count: size
16})
17
18async function run () {
19 const promises = new Set()
20 for (let i = 0; i < iterations; i++) {
21 promises.add(threadPool.exec(data))
22 }
23 await Promise.all(promises)
24 // eslint-disable-next-line n/no-process-exit
25 process.exit()
26}
27
479ba9f6 28await executeAsyncFn(run)