Commit | Line | Data |
---|---|---|
76e2e978 | 1 | import { ThreadPool } from 'nanothreads' |
91a40166 | 2 | import { BenchmarkDefaults, executeAsyncFn } from './utils.mjs' |
76e2e978 | 3 | import functionToBench from './functions/function-to-bench.js' |
479ba9f6 | 4 | |
91a40166 JB |
5 | const size = parseInt(process.env.POOL_SIZE) || BenchmarkDefaults.poolSize |
6 | const numIterations = | |
7 | parseInt(process.env.NUM_ITERATIONS) || BenchmarkDefaults.numIterations | |
76e2e978 JB |
8 | const 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 | ||
14 | const threadPool = new ThreadPool({ | |
15 | task: functionToBench, | |
16 | count: size | |
17 | }) | |
18 | ||
19 | async 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 | 29 | await executeAsyncFn(run) |