| 1 | // IMPORT LIBRARIES |
| 2 | const workerpool = require('workerpool') |
| 3 | // FINISH IMPORT LIBRARIES |
| 4 | const size = process.env.POOL_SIZE |
| 5 | const iterations = process.env.NUM_ITERATIONS |
| 6 | const dataArray = ['MYBENCH', process.env['TASK_TYPE']] |
| 7 | |
| 8 | const workerPool = workerpool.pool( |
| 9 | './workers/workerpool/function-to-bench-worker.js', |
| 10 | { |
| 11 | minWorkers: Number(size), |
| 12 | maxWorkers: Number(size), |
| 13 | workerType: 'thread' |
| 14 | } |
| 15 | ) |
| 16 | |
| 17 | async function run () { |
| 18 | const promises = [] |
| 19 | for (let i = 0; i < iterations; i++) { |
| 20 | promises.push(workerPool.exec('functionToBench', dataArray)) |
| 21 | } |
| 22 | await Promise.all(promises) |
| 23 | process.exit() |
| 24 | } |
| 25 | |
| 26 | run() |