1 const FixedThreadPool
= require('../lib/fixed')
2 const DynamicThreadPool
= require('../lib/dynamic')
3 const Pool
= require('worker-threads-pool')
8 const externalPool
= new Pool({ max
: size
})
9 const fixedPool
= new FixedThreadPool(size
, './yourWorker.js', {
12 const dynamicPool
= new DynamicThreadPool(
20 const workerData
= { proof
: 'ok' }
23 async
function fixedTest () {
25 const time
= Date
.now()
26 for (let i
= 0; i
<= tasks
; i
++) {
27 fixedPool
.execute(workerData
).then(res
=> {
29 if (executions
=== tasks
) {
31 `Fixed pool take ${Date.now() - time} to work on ${executions} tasks`
38 async
function dynamicTest () {
40 const time
= Date
.now()
41 for (let i
= 0; i
<= tasks
; i
++) {
42 dynamicPool
.execute(workerData
).then(res
=> {
44 if (executions
=== tasks
) {
46 `Dynamic pool take ${Date.now() -
47 time} to work on ${executions} tasks`
54 async
function externalPoolTest () {
56 const time
= Date
.now()
57 for (let i
= 0; i
<= tasks
; i
++) {
58 new Promise((resolve
, reject
) => {
60 './externalWorker.js',
61 { workerData
: workerData
},
66 worker
.on('error', reject
)
67 worker
.on('message', res
=> {
74 if (tasks
=== executions
) {
76 `External pool take ${Date.now() -
77 time} to work on ${executions} tasks`
84 async
function test () {