e0daca2d0aa84a85387f23414b884b1c57170f2d
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
, './yourWorker.js', {
12 const dynamicPool
= new DynamicThreadPool(
18 const workerData
= { proof
: 'ok' }
20 // wait some seconds before start, my pools need to load threads !!!
21 setTimeout(async () => {
26 async
function fixedTest () {
27 return new Promise((resolve
, reject
) => {
29 for (let i
= 0; i
<= tasks
; i
++) {
30 fixedPool
.execute(workerData
).then(res
=> {
32 if (executions
=== tasks
) {
40 async
function dynamicTest () {
41 return new Promise((resolve
, reject
) => {
43 for (let i
= 0; i
<= tasks
; i
++) {
44 dynamicPool
.execute(workerData
).then(res
=> {
46 if (executions
=== tasks
) {
54 async
function test () {
57 .add('PioardiStaticPool', async
function () {
60 .add('PioardiDynamicPool', async
function () {
64 .on('cycle', function (event
) {
65 console
.log(String(event
.target
))
67 .on('complete', function () {
68 this.filter('fastest').map('name')
69 console
.log('Fastest is ' + this.filter('fastest').map('name'))