1 const Benchmark
= require('benchmark')
2 const suite
= new Benchmark
.Suite()
3 const { FixedThreadPool
} = require('../lib/index')
4 const { DynamicThreadPool
} = require('../lib/index')
8 const LIST_FORMATTER
= new Intl
.ListFormat('en-US', {
14 const fixedPool
= new FixedThreadPool(size
, './threadWorker.js', {
17 const dynamicPool
= new DynamicThreadPool(
23 const workerData
= { proof
: 'ok' }
25 // wait some seconds before start, my pools need to load threads !!!
26 setTimeout(async () => {
31 async
function fixedTest () {
32 return new Promise((resolve
, reject
) => {
34 for (let i
= 0; i
<= tasks
; i
++) {
39 if (executions
=== tasks
) {
40 return resolve('FINISH')
51 async
function dynamicTest () {
52 return new Promise((resolve
, reject
) => {
54 for (let i
= 0; i
<= tasks
; i
++) {
59 if (executions
=== tasks
) {
60 return resolve('FINISH')
64 .catch(err
=> console
.error(err
))
69 async
function test () {
72 .add('PioardiStaticPool', async
function () {
75 .add('PioardiDynamicPool', async
function () {
79 .on('cycle', function (event
) {
80 console
.log(event
.target
.toString())
82 .on('complete', function () {
85 LIST_FORMATTER
.format(this.filter('fastest').map('name'))
87 // eslint-disable-next-line no-process-exit