Commit | Line | Data |
---|---|---|
8fca9288 | 1 | import workerpool from 'workerpool' |
91a40166 | 2 | import { BenchmarkDefaults, executeAsyncFn } from './utils.mjs' |
479ba9f6 | 3 | |
91a40166 JB |
4 | const size = parseInt(process.env.POOL_SIZE) || BenchmarkDefaults.poolSize |
5 | const numIterations = | |
6 | parseInt(process.env.NUM_ITERATIONS) || BenchmarkDefaults.numIterations | |
6bd72cd0 JB |
7 | const dataArray = [ |
8 | 'MYBENCH', | |
91a40166 JB |
9 | process.env.TASK_TYPE || BenchmarkDefaults.taskType, |
10 | parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize | |
6bd72cd0 | 11 | ] |
144f78e0 JB |
12 | |
13 | const workerPool = workerpool.pool( | |
8fca9288 | 14 | './workers/workerpool/function-to-bench-worker.mjs', |
144f78e0 | 15 | { |
02749105 JB |
16 | minWorkers: Math.floor(size / 2), |
17 | maxWorkers: size, | |
144f78e0 JB |
18 | workerType: 'thread' |
19 | } | |
20 | ) | |
21 | ||
22 | async function run () { | |
1655b92e | 23 | const promises = new Set() |
91a40166 | 24 | for (let i = 0; i < numIterations; i++) { |
1655b92e | 25 | promises.add(workerPool.exec('functionToBench', dataArray)) |
144f78e0 JB |
26 | } |
27 | await Promise.all(promises) | |
2f8c5b5c | 28 | // eslint-disable-next-line n/no-process-exit |
144f78e0 JB |
29 | process.exit() |
30 | } | |
31 | ||
479ba9f6 | 32 | await executeAsyncFn(run) |