Commit | Line | Data |
---|---|---|
be0676b3 APA |
1 | // IMPORT LIBRARIES |
2 | const { DynamicPool, StaticPool } = require('node-worker-threads-pool') | |
3 | // FINISH IMPORT LIBRARIES | |
4 | // IMPORT FUNCTION TO BENCH | |
5 | const functionToBench = require('./functions/json-stringify') | |
6 | // FINISH IMPORT FUNCTION TO BENCH | |
7 | const size = process.env.POOL_SIZE | |
8 | const iterations = process.env.NUM_ITERATIONS | |
9 | const data = { | |
10 | test: 'MYBENCH' | |
11 | } | |
12 | ||
13 | const pool = new DynamicPool(Number(size)) | |
14 | ||
15 | async function run () { | |
16 | const promises = [] | |
17 | for (let i = 0; i < iterations; i++) { | |
18 | promises.push( | |
19 | pool.exec({ | |
20 | task: functionToBench, | |
21 | param: data | |
22 | }) | |
23 | ) | |
24 | } | |
25 | await Promise.all(promises) | |
26 | process.exit() | |
27 | } | |
28 | ||
29 | run() |