-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfixed-workerpool.mjs
More file actions
37 lines (32 loc) · 926 Bytes
/
fixed-workerpool.mjs
File metadata and controls
37 lines (32 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import workerpool from 'workerpool'
import { BenchmarkDefaults, executeAsyncFn } from './utils.cjs'
const size =
Number.parseInt(process.env.POOL_SIZE) || BenchmarkDefaults.poolSize
const numIterations =
Number.parseInt(process.env.NUM_ITERATIONS) || BenchmarkDefaults.numIterations
const dataArray = [
'MYBENCH',
process.env.TASK_TYPE || BenchmarkDefaults.taskType,
Number.parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize,
]
const workerPool = workerpool.pool(
'./workers/workerpool/function-to-bench-worker.mjs',
{
maxWorkers: size,
minWorkers: size,
workerType: 'thread',
}
)
/**
*
*/
const run = async () => {
const promises = new Set()
for (let i = 0; i < numIterations; i++) {
promises.add(workerPool.exec('functionToBench', dataArray))
}
await Promise.all(promises)
// eslint-disable-next-line n/no-process-exit
process.exit()
}
await executeAsyncFn(run)