3b497af5ed9306223841ffe6b4ceb31a9e07f29e
[poolifier.git] / benchmarks / versus-external-pools / fixed-nanothreads.mjs
1 import { ThreadPool } from 'nanothreads'
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 threadPool = new ThreadPool({
15 task: functionToBench,
16 count: size
17 })
18
19 async function run () {
20 const promises = new Set()
21 for (let i = 0; i < numIterations; i++) {
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
29 await executeAsyncFn(run)