perf: remove unneeded class indirection for dynamic pool in worker
[poolifier.git] / benchmarks / versus-external-pools / fixed-microjob.js
1 // IMPORT LIBRARIES
2 const { job, start } = require('microjob')
3 // FINISH IMPORT LIBRARIES
4 // IMPORT FUNCTION TO BENCH
5 const functionToBench = require('./functions/function-to-bench')
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 async function run () {
16 await start({ maxWorkers: size })
17 const promises = []
18 for (let i = 0; i < iterations; i++) {
19 promises.push(
20 job(
21 data => {
22 functionToBench(data)
23 },
24 { data, ctx: { functionToBench } }
25 )
26 )
27 }
28 await Promise.all(promises)
29 // eslint-disable-next-line n/no-process-exit
30 process.exit()
31 }
32
33 run()