Commit | Line | Data |
---|---|---|
8fca9288 | 1 | import { StaticPool } from 'node-worker-threads-pool' |
91a40166 | 2 | import { BenchmarkDefaults, executeAsyncFn } from './utils.mjs' |
bea2d6e3 | 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 | |
be0676b3 | 8 | const data = { |
9f7e7a99 | 9 | test: 'MYBENCH', |
91a40166 JB |
10 | taskType: process.env.TASK_TYPE || BenchmarkDefaults.taskType, |
11 | taskSize: parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize | |
be0676b3 APA |
12 | } |
13 | ||
4bb5e44d | 14 | const staticPool = new StaticPool({ |
7a6a0a96 | 15 | size, |
be0676b3 APA |
16 | task: functionToBench |
17 | }) | |
18 | ||
19 | async function run () { | |
1655b92e | 20 | const promises = new Set() |
91a40166 | 21 | for (let i = 0; i < numIterations; i++) { |
4bb5e44d | 22 | promises.add(staticPool.exec(data)) |
be0676b3 APA |
23 | } |
24 | await Promise.all(promises) | |
2f8c5b5c | 25 | // eslint-disable-next-line n/no-process-exit |
be0676b3 APA |
26 | process.exit() |
27 | } | |
28 | ||
479ba9f6 | 29 | await executeAsyncFn(run) |