Commit | Line | Data |
---|---|---|
8fca9288 | 1 | import { DynamicPool } from 'node-worker-threads-pool' |
479ba9f6 | 2 | import { executeAsyncFn } from '../benchmarks-utils.mjs' |
bea2d6e3 | 3 | import functionToBench from './functions/function-to-bench.js' |
479ba9f6 | 4 | |
6bd72cd0 JB |
5 | const size = parseInt(process.env.POOL_SIZE) |
6 | const iterations = parseInt(process.env.NUM_ITERATIONS) | |
be0676b3 | 7 | const data = { |
9f7e7a99 | 8 | test: 'MYBENCH', |
7a6a0a96 | 9 | taskType: process.env.TASK_TYPE, |
6bd72cd0 | 10 | taskSize: parseInt(process.env.TASK_SIZE) |
be0676b3 APA |
11 | } |
12 | ||
4bb5e44d | 13 | const dynamicPool = new DynamicPool(size) |
be0676b3 APA |
14 | |
15 | async function run () { | |
1655b92e | 16 | const promises = new Set() |
be0676b3 | 17 | for (let i = 0; i < iterations; i++) { |
1655b92e | 18 | promises.add( |
4bb5e44d | 19 | dynamicPool.exec({ |
be0676b3 | 20 | task: functionToBench, |
ae55bb0e JB |
21 | param: data, |
22 | timeout: 60000 // this is the same as poolifier default | |
be0676b3 APA |
23 | }) |
24 | ) | |
25 | } | |
26 | await Promise.all(promises) | |
2f8c5b5c | 27 | // eslint-disable-next-line n/no-process-exit |
be0676b3 APA |
28 | process.exit() |
29 | } | |
30 | ||
479ba9f6 | 31 | await executeAsyncFn(run) |