Create SECURITY.md
[poolifier.git] / benchmarks / versus-external-pools / threadjs.js
CommitLineData
75876e4c
APA
1// IMPORT LIBRARIES
2const { spawn, Thread, Worker } = require('threads')
3// FINISH IMPORT LIBRARIES
4const size = process.env.POOL_SIZE
5const iterations = process.env.NUM_ITERATIONS
6const data = {
7 test: 'MYBENCH',
8 taskType: process.env['TASK_TYPE']
9}
10
11// Threads.js is not really a pool so we need to write few additional code
12const workers = []
13async function poolify () {
14 for (let i = 0; i < size ; i++ ){
15 const worker = await spawn(new Worker("./workers/threadjs/function-to-bench-worker.js"))
16 workers.push(worker)
17 }
18}
19
20
21async function run () {
22 await poolify()
23 const promises = []
24 for (let i = 0; i < iterations; i++) {
25 const worker = workers[(i % size)]
26 promises.push(worker.exposedFunction(data))
27 }
28 await Promise.all(promises)
29 process.exit()
30}
31
32run()