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