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 StaticPool({ | |
14 | size: Number(size), | |
15 | task: functionToBench | |
16 | }) | |
17 | ||
18 | async function run () { | |
19 | const promises = [] | |
20 | for (let i = 0; i < iterations; i++) { | |
21 | promises.push(pool.exec(data)) | |
22 | } | |
23 | await Promise.all(promises) | |
24 | process.exit() | |
25 | } | |
26 | ||
27 | run() |