Benchmarks and performance enhancements (#209)
[poolifier.git] / benchmarks / versus-external-pools / static-suchmokuo-node-worker-threads-pool.js
CommitLineData
be0676b3
APA
1// IMPORT LIBRARIES
2const { DynamicPool, StaticPool } = require('node-worker-threads-pool')
3// FINISH IMPORT LIBRARIES
4// IMPORT FUNCTION TO BENCH
5const functionToBench = require('./functions/json-stringify')
6// FINISH IMPORT FUNCTION TO BENCH
7const size = process.env.POOL_SIZE
8const iterations = process.env.NUM_ITERATIONS
9const data = {
10 test: 'MYBENCH'
11}
12
13const pool = new StaticPool({
14 size: Number(size),
15 task: functionToBench
16})
17
18async 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
27run()