X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=benchmarks%2FmyBench.js;fp=benchmarks%2FmyBench.js;h=8835f1f5d4cec31feba03012fc7974df02810f91;hb=cf9aa6c3340ad00792aa3c5e1a9d047cd0140fc2;hp=9c1d713fc6820f8e3cefaa64a5785b13d50ae8ec;hpb=2cb4627928795847a7e4f867c6fa8f0781d062c9;p=poolifier.git diff --git a/benchmarks/myBench.js b/benchmarks/myBench.js index 9c1d713f..8835f1f5 100644 --- a/benchmarks/myBench.js +++ b/benchmarks/myBench.js @@ -6,8 +6,15 @@ const size = 16 // pools const externalPool = new Pool({ max: size }) -const fixedPool = new FixedThreadPool(size, './yourWorker.js', { maxTasks: 10000 }) -const dynamicPool = new DynamicThreadPool(size / 2, size * 3, './yourWorker.js', { maxTasks: 10000 }) +const fixedPool = new FixedThreadPool(size, './yourWorker.js', { + maxTasks: 10000 +}) +const dynamicPool = new DynamicThreadPool( + size / 2, + size * 3, + './yourWorker.js', + { maxTasks: 10000 } +) // data const workerData = { proof: 'ok' } @@ -19,7 +26,11 @@ async function fixedTest () { for (let i = 0; i <= tasks; i++) { fixedPool.execute(workerData).then(res => { executions++ - if (executions === tasks) console.log(`Fixed pool take ${Date.now() - time} to work on ${executions} tasks`) + if (executions === tasks) { + console.log( + `Fixed pool take ${Date.now() - time} to work on ${executions} tasks` + ) + } }) } } @@ -30,7 +41,12 @@ async function dynamicTest () { for (let i = 0; i <= tasks; i++) { dynamicPool.execute(workerData).then(res => { executions++ - if (executions === tasks) console.log(`Dynamic pool take ${Date.now() - time} to work on ${executions} tasks`) + if (executions === tasks) { + console.log( + `Dynamic pool take ${Date.now() - + time} to work on ${executions} tasks` + ) + } }) } } @@ -40,18 +56,27 @@ async function externalPoolTest () { const time = Date.now() for (let i = 0; i <= tasks; i++) { new Promise((resolve, reject) => { - externalPool.acquire('./externalWorker.js', { workerData: workerData }, (err, worker) => { - if (err) { - return reject(err) + externalPool.acquire( + './externalWorker.js', + { workerData: workerData }, + (err, worker) => { + if (err) { + return reject(err) + } + worker.on('error', reject) + worker.on('message', res => { + executions++ + resolve(res) + }) } - worker.on('error', reject) - worker.on('message', res => { - executions++ - resolve(res) - }) - }) + ) }).then(res => { - if (tasks === executions) console.log(`External pool take ${Date.now() - time} to work on ${executions} tasks`) + if (tasks === executions) { + console.log( + `External pool take ${Date.now() - + time} to work on ${executions} tasks` + ) + } }) } }