X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=benchmarks%2Finternal%2Fthread%2Ffixed.js;h=617aa7e5950952c241c2c98a091e2cf8965553b6;hb=e843b9042b77e0e4e17c193820a3e05ffc92cffe;hp=8db41acbde4f40cb38104aaedc009d87c3b43111;hpb=be0676b3936d75f22ce55b0f71a1fb03d008a01c;p=poolifier.git diff --git a/benchmarks/internal/thread/fixed.js b/benchmarks/internal/thread/fixed.js index 8db41acb..617aa7e5 100644 --- a/benchmarks/internal/thread/fixed.js +++ b/benchmarks/internal/thread/fixed.js @@ -1,31 +1,33 @@ -const { FixedThreadPool } = require('../../../lib/index') +const { + FixedThreadPool, + WorkerChoiceStrategies +} = require('../../../lib/index') +const { runPoolifierTest } = require('../benchmark-utils') const size = 30 +const numberOfTasks = 1 -const fixedPool = new FixedThreadPool(size, './worker.js', { - maxTasks: 10000 -}) +const fixedPool = new FixedThreadPool( + size, + './benchmarks/internal/thread/worker.js' +) + +const fixedPoolLessRecentlyUsed = new FixedThreadPool( + size, + './benchmarks/internal/thread/worker.js', + { workerChoiceStrategy: WorkerChoiceStrategies.LESS_RECENTLY_USED } +) async function fixedThreadTest ( - { tasks, workerData } = { tasks: 1, workerData: { proof: 'ok' } } + { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } } +) { + return runPoolifierTest(fixedPool, { tasks, workerData }) +} + +async function fixedThreadTestLessRecentlyUsed ( + { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } } ) { - 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) - }) - } - }) + return runPoolifierTest(fixedPoolLessRecentlyUsed, { tasks, workerData }) } -module.exports = { fixedThreadTest } +module.exports = { fixedThreadTest, fixedThreadTestLessRecentlyUsed }