Commit | Line | Data |
---|---|---|
8fca9288 | 1 | import { DynamicPool } 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 dynamicPool = new DynamicPool(size) |
be0676b3 APA |
15 | |
16 | async function run () { | |
1655b92e | 17 | const promises = new Set() |
91a40166 | 18 | for (let i = 0; i < numIterations; i++) { |
1655b92e | 19 | promises.add( |
4bb5e44d | 20 | dynamicPool.exec({ |
be0676b3 | 21 | task: functionToBench, |
ae55bb0e JB |
22 | param: data, |
23 | timeout: 60000 // this is the same as poolifier default | |
be0676b3 APA |
24 | }) |
25 | ) | |
26 | } | |
27 | await Promise.all(promises) | |
2f8c5b5c | 28 | // eslint-disable-next-line n/no-process-exit |
be0676b3 APA |
29 | process.exit() |
30 | } | |
31 | ||
479ba9f6 | 32 | await executeAsyncFn(run) |