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