Commit | Line | Data |
---|---|---|
935f9dbf | 1 | import Tinypool from 'tinypool' |
91a40166 | 2 | import { BenchmarkDefaults, executeAsyncFn } from './utils.mjs' |
479ba9f6 | 3 | |
91a40166 JB |
4 | const size = parseInt(process.env.POOL_SIZE) || BenchmarkDefaults.poolSize |
5 | const numIterations = | |
6 | parseInt(process.env.NUM_ITERATIONS) || BenchmarkDefaults.numIterations | |
935f9dbf JB |
7 | const data = { |
8 | test: 'MYBENCH', | |
91a40166 JB |
9 | taskType: process.env.TASK_TYPE || BenchmarkDefaults.taskType, |
10 | taskSize: parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize | |
935f9dbf JB |
11 | } |
12 | ||
13 | const tinypool = new Tinypool({ | |
8fca9288 | 14 | filename: './workers/tinypool/function-to-bench-worker.mjs', |
02749105 JB |
15 | minThreads: Math.floor(size / 2), |
16 | maxThreads: size, | |
935f9dbf JB |
17 | idleTimeout: 60000 // this is the same as poolifier default |
18 | }) | |
19 | ||
935f9dbf | 20 | async function run () { |
1655b92e | 21 | const promises = new Set() |
91a40166 | 22 | for (let i = 0; i < numIterations; i++) { |
1655b92e | 23 | promises.add(tinypool.run(data)) |
935f9dbf JB |
24 | } |
25 | await Promise.all(promises) | |
26 | // eslint-disable-next-line n/no-process-exit | |
27 | process.exit() | |
28 | } | |
29 | ||
479ba9f6 | 30 | await executeAsyncFn(run) |