1 const Benchmark
= require('benchmark')
2 const suite
= new Benchmark
.Suite()
3 const FixedThreadPool
= require('../lib/fixed')
4 const DynamicThreadPool
= require('../lib/dynamic')
9 const fixedPool
= new FixedThreadPool(size
,
10 './yourWorker.js', { maxTasks
: 10000 })
11 const dynamicPool
= new DynamicThreadPool(size
/ 2, size
* 3, './yourWorker.js', { maxTasks
: 10000 })
12 const workerData
= { proof
: 'ok' }
14 // wait some seconds before start, my pools need to load threads !!!
15 setTimeout(async () => {
20 async
function fixedTest () {
21 return new Promise((resolve
, reject
) => {
23 for (let i
= 0; i
<= tasks
; i
++) {
24 fixedPool
.execute(workerData
).then(res
=> {
26 if (executions
=== tasks
) {
34 async
function dynamicTest () {
35 return new Promise((resolve
, reject
) => {
37 for (let i
= 0; i
<= tasks
; i
++) {
38 dynamicPool
.execute(workerData
).then(res
=> {
40 if (executions
=== tasks
) {
48 async
function test () {
50 suite
.add('PioardiStaticPool', async
function () {
53 .add('PioardiDynamicPool', async
function () {
57 .on('cycle', function (event
) {
58 console
.log(String(event
.target
))
60 .on('complete', function () {
61 this.filter('fastest').map('name')
62 console
.log('Fastest is ' + this.filter('fastest').map('name'))