X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=benchmarks%2Fbench.js;h=f8d933813a8b393692a124bbece9243aec244681;hb=e901162fa610e2af305aac504549580b2de48cab;hp=39d743ad1293b7c851cd6e4180ae2c8ad6047ff5;hpb=57df5469cb6f9ffd7c3501f026f2659b3cf88f06;p=poolifier.git diff --git a/benchmarks/bench.js b/benchmarks/bench.js index 39d743ad..f8d93381 100644 --- a/benchmarks/bench.js +++ b/benchmarks/bench.js @@ -1,15 +1,15 @@ 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/fixed') -const Pool = require('worker-threads-pool') -const size = 80 -const externalPool = new Pool({ max: size }) -const fixedPool = new FixedThreadPool(size, - './yourWorker.js', { maxTasks: 10000 }) -// const dynamicPool = new DynamicThreadPool(size, size * 2, './yourWorker.js', { maxTasks: 10000 }) -const workerData = { proof: 'ok' } -let executions = 0 +const LIST_FORMATTER = new Intl.ListFormat('en-US', { + style: 'long', + type: 'conjunction' +}) // wait some seconds before start, my pools need to load threads !!! setTimeout(async () => { @@ -18,41 +18,30 @@ setTimeout(async () => { async function test () { // add tests - suite.add('PioardiStaticPool', async function () { - executions++ - await fixedPool.execute(workerData) - }) - .add('ExternalPool', async function () { - await new Promise((resolve, reject) => { - externalPool.acquire('./externalWorker.js', { workerData: workerData }, (err, worker) => { - if (err) { - return reject(err) - } - worker.on('error', reject) - worker.on('message', res => { - resolve(res) - }) - }) - }) + suite + .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 dynamicPool.execute(workerData) - }) */ - // add listeners + .add('Pioardi:Dynamic:ClusterPool', async function () { + await dynamicClusterTest() + }) + // add listeners .on('cycle', function (event) { - console.log(String(event.target)) + console.log(event.target.toString()) }) .on('complete', function () { - console.log(executions) - this.filter('fastest').map('name') - console.log('Fastest is ' + this.filter('fastest').map('name')) + console.log( + 'Fastest is ' + + LIST_FORMATTER.format(this.filter('fastest').map('name')) + ) + // eslint-disable-next-line no-process-exit + process.exit() }) - // run async - .run({ async: true }) + .run() } - -process.on('SIGKILL', () => { - fixedPool.destroy() - externalPool.destroy() -})