From: Jérôme Benoit Date: Sun, 31 Mar 2024 14:08:15 +0000 (+0200) Subject: refactor(benchmark): improve benchmark.js code X-Git-Tag: v3.1.28~7 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=fe7488e988f14a6f744aeadff61c2df9bd2239eb;p=poolifier.git refactor(benchmark): improve benchmark.js code Signed-off-by: Jérôme Benoit --- diff --git a/benchmarks/benchmarks-utils.mjs b/benchmarks/benchmarks-utils.mjs index f04e4d0f..96d597cf 100644 --- a/benchmarks/benchmarks-utils.mjs +++ b/benchmarks/benchmarks-utils.mjs @@ -83,9 +83,36 @@ export const runPoolifierBenchmarkBenchmarkJs = async ( { taskExecutions, workerData } ) => { return await new Promise((resolve, reject) => { - const pool = buildPoolifierPool(workerType, poolType, poolSize) + let pool = buildPoolifierPool(workerType, poolType, poolSize) try { - const suite = new Benchmark.Suite(name) + const suite = new Benchmark.Suite(name, { + onComplete: () => { + const destroyTimeout = setTimeout(() => { + console.error('Pool destroy timeout reached (30s)') + resolve() + pool = undefined + }, 30000) + pool + .destroy() + .then(resolve) + .catch(reject) + .finally(() => { + clearTimeout(destroyTimeout) + }) + .catch(() => {}) + }, + onCycle: event => { + console.info(event.target.toString()) + }, + onError: event => { + pool + .destroy() + .then(() => { + return reject(event.target.error) + }) + .catch(() => {}) + } + }) for (const workerChoiceStrategy of Object.values( WorkerChoiceStrategies )) { @@ -96,7 +123,7 @@ export const runPoolifierBenchmarkBenchmarkJs = async ( Measurements.elu ]) { suite.add( - `${name} with ${workerChoiceStrategy}, with ${measurement} and ${ + `${name} with ${workerChoiceStrategy}, with measurement ${measurement} and ${ enableTasksQueue ? 'with' : 'without' } tasks queue`, async () => { @@ -151,28 +178,13 @@ export const runPoolifierBenchmarkBenchmarkJs = async ( } } suite - .on('cycle', event => { - console.info(event.target.toString()) - }) .on('complete', function () { console.info( 'Fastest is ' + LIST_FORMATTER.format(this.filter('fastest').map('name')) ) - const destroyTimeout = setTimeout(() => { - console.error('Pool destroy timeout reached (30s)') - resolve() - }, 30000) - pool - .destroy() - .then(resolve) - .catch(reject) - .finally(() => { - clearTimeout(destroyTimeout) - }) - .catch(() => {}) }) - .run({ async: true }) + .run({ async: true, queued: true }) } catch (error) { pool .destroy()