X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=benchmarks%2Fbench.js;h=f8d933813a8b393692a124bbece9243aec244681;hb=e901162fa610e2af305aac504549580b2de48cab;hp=017ac20be223e0fd26faba804e54c2329dcf931c;hpb=583a27ce13d67cc33ded52f46fe1665c64a8fec7;p=poolifier.git diff --git a/benchmarks/bench.js b/benchmarks/bench.js index 017ac20b..f8d93381 100644 --- a/benchmarks/bench.js +++ b/benchmarks/bench.js @@ -1,79 +1,35 @@ const Benchmark = require('benchmark') +const { dynamicClusterTest } = require('./cluster/dynamic') +const { fixedClusterTest } = require('./cluster/fixed') +const { dynamicThreadTest } = require('./thread/dynamic') +const { fixedThreadTest } = require('./thread/fixed') + const suite = new Benchmark.Suite() -const { FixedThreadPool } = require('../lib/index') -const { DynamicThreadPool } = require('../lib/index') -const size = 30 -const tasks = 1 const LIST_FORMATTER = new Intl.ListFormat('en-US', { style: 'long', type: 'conjunction' }) -// pools -const fixedPool = new FixedThreadPool(size, './threadWorker.js', { - maxTasks: 10000 -}) -const dynamicPool = new DynamicThreadPool( - size / 2, - size * 3, - './threadWorker.js', - { maxTasks: 10000 } -) -const workerData = { proof: 'ok' } - // wait some seconds before start, my pools need to load threads !!! setTimeout(async () => { test() }, 3000) -// fixed pool proof -async function fixedTest () { - return new Promise((resolve, reject) => { - let executions = 0 - for (let i = 0; i <= tasks; i++) { - fixedPool - .execute(workerData) - .then(res => { - executions++ - if (executions === tasks) { - return resolve('FINISH') - } - return null - }) - .catch(err => { - console.error(err) - }) - } - }) -} - -async function dynamicTest () { - return new Promise((resolve, reject) => { - let executions = 0 - for (let i = 0; i <= tasks; i++) { - dynamicPool - .execute(workerData) - .then(res => { - executions++ - if (executions === tasks) { - return resolve('FINISH') - } - return null - }) - .catch(err => console.error(err)) - } - }) -} - async function test () { // add tests suite - .add('PioardiStaticPool', async function () { - await fixedTest() + .add('Pioardi:Static:ThreadPool', async function () { + await fixedThreadTest() + }) + .add('Pioardi:Dynamic:ThreadPool', async function () { + await dynamicThreadTest() + }) + .add('Pioardi:Static:ClusterPool', async function () { + await fixedClusterTest() }) - .add('PioardiDynamicPool', async function () { - await dynamicTest() + .add('Pioardi:Dynamic:ClusterPool', async function () { + await dynamicClusterTest() }) // add listeners .on('cycle', function (event) { @@ -87,6 +43,5 @@ async function test () { // eslint-disable-next-line no-process-exit process.exit() }) - // run async - .run({ async: true }) + .run() }