X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=benchmarks%2Fbench.js;h=2ad7f22c5e47ec7827366ed3c95b21a3402c06cf;hb=17a9a09416d6c07f560eb0c79bd031d8c0125d4e;hp=e0daca2d0aa84a85387f23414b884b1c57170f2d;hpb=cf9aa6c3340ad00792aa3c5e1a9d047cd0140fc2;p=poolifier.git diff --git a/benchmarks/bench.js b/benchmarks/bench.js index e0daca2d..2ad7f22c 100644 --- a/benchmarks/bench.js +++ b/benchmarks/bench.js @@ -1,73 +1,47 @@ 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 DynamicThreadPool = require('../lib/dynamic') -const size = 30 -const tasks = 1 -// pools -const fixedPool = new FixedThreadPool(size, './yourWorker.js', { - maxTasks: 10000 +const LIST_FORMATTER = new Intl.ListFormat('en-US', { + style: 'long', + type: 'conjunction' }) -const dynamicPool = new DynamicThreadPool( - size / 2, - size * 3, - './yourWorker.js', - { maxTasks: 10000 } -) -const workerData = { proof: 'ok' } -// wait some seconds before start, my pools need to load threads !!! +// Wait some seconds before start, 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) { - resolve('FINISH') - } - }) - } - }) -} - -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) { - resolve('FINISH') - } - }) - } - }) -} - async function test () { - // add tests + // 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 + // Add listeners .on('cycle', function (event) { - console.log(String(event.target)) + console.log(event.target.toString()) }) .on('complete', function () { - 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() }