-
Notifications
You must be signed in to change notification settings - Fork 0
/
dynamic-concurrent.js.mjs
40 lines (34 loc) · 1.05 KB
/
dynamic-concurrent.js.mjs
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
38
39
40
import { concurrent } from '@bitair/concurrent.js'
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 data = {
taskSize:
Number.parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize,
taskType: process.env.TASK_TYPE || BenchmarkDefaults.taskType,
test: 'MYBENCH',
}
concurrent.config({
maxThreads: size,
minThreads: Math.floor(size / 2),
threadIdleTimeout: BenchmarkDefaults.idleTimeout,
})
const functionToBenchModule = concurrent.import(
new URL('./functions/index.mjs', import.meta.url)
)
/**
*
*/
const run = async () => {
const promises = new Set()
for (let i = 0; i < numIterations; i++) {
const { functionToBench } = await functionToBenchModule.load()
promises.add(functionToBench(data))
}
await Promise.all(promises)
// eslint-disable-next-line n/no-process-exit
process.exit()
}
await executeAsyncFn(run)