From: Jérôme Benoit Date: Mon, 10 Oct 2022 20:44:13 +0000 (+0200) Subject: Enchance benchmarking code X-Git-Tag: v2.3.1~31 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=2d2e32c20d55c1b81771659fd81004bd7ca34b73;p=poolifier.git Enchance benchmarking code Signed-off-by: Jérôme Benoit --- diff --git a/.github/dependabot.yml b/.github/dependabot.yml index b4edbf73..cd90cc53 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -22,3 +22,16 @@ updates: - 'Shinigami92' - 'jerome-benoit' versioning-strategy: increase + - package-ecosystem: 'npm' + directory: '/benchmarks/versus-external-pools' + schedule: + interval: 'daily' + labels: + - 'dependencies' + - 'benchmarks' + - 'nocombine' + reviewers: + - 'pioardi' + - 'Shinigami92' + - 'jerome-benoit' + versioning-strategy: increase diff --git a/.lintstagedrc.js b/.lintstagedrc.js index 433ce7f0..67f3a844 100644 --- a/.lintstagedrc.js +++ b/.lintstagedrc.js @@ -1,7 +1,7 @@ module.exports = { '**/*.{js,mjs,ts}': ['eslint --cache --fix'], '**/*.{json,md,yml}': [ - 'prettier --loglevel silent --write', + 'prettier --write', 'prettierx --write' ] } diff --git a/benchmarks/internal/benchmark-utils.js b/benchmarks/internal/benchmark-utils.js index 7cb4e54f..a7e4ddec 100644 --- a/benchmarks/internal/benchmark-utils.js +++ b/benchmarks/internal/benchmark-utils.js @@ -1,3 +1,9 @@ +const WorkerFunctions = { + jsonIntegerSerialization: 'jsonIntegerSerialization', + fibonacci: 'fibonacci', + factorial: 'factorial' +} + async function runPoolifierTest (pool, { tasks, workerData }) { return new Promise((resolve, reject) => { let executions = 0 @@ -62,16 +68,28 @@ function factorial (n) { } } +function executeWorkerFunction (data) { + switch (data.function) { + case WorkerFunctions.jsonIntegerSerialization: + return jsonIntegerSerialization(data.n || 1000) + case WorkerFunctions.fibonacci: + return fibonacci(data.n || 50) + case WorkerFunctions.factorial: + return factorial(data.n || 1000) + default: + throw new Error('Unknown worker function') + } +} + const LIST_FORMATTER = new Intl.ListFormat('en-US', { style: 'long', type: 'conjunction' }) module.exports = { - runPoolifierTest, - jsonIntegerSerialization, + LIST_FORMATTER, + WorkerFunctions, + executeWorkerFunction, generateRandomInteger, - fibonacci, - factorial, - LIST_FORMATTER + runPoolifierTest } diff --git a/benchmarks/internal/cluster/worker.js b/benchmarks/internal/cluster/worker.js index 0235affa..29005f9c 100644 --- a/benchmarks/internal/cluster/worker.js +++ b/benchmarks/internal/cluster/worker.js @@ -1,12 +1,14 @@ 'use strict' const { isMaster } = require('cluster') const { ClusterWorker } = require('../../../lib/index') -const { jsonIntegerSerialization } = require('../benchmark-utils') +const { WorkerFunctions, executeWorkerFunction } = require('../benchmark-utils') const debug = false function yourFunction (data) { - jsonIntegerSerialization(1000) + data = data || {} + data.function = data.function || WorkerFunctions.jsonIntegerSerialization + executeWorkerFunction(data) debug === true && console.debug('This is the main thread ' + isMaster) return { ok: 1 } } diff --git a/benchmarks/internal/thread/worker.js b/benchmarks/internal/thread/worker.js index 5196ca38..902cecc1 100644 --- a/benchmarks/internal/thread/worker.js +++ b/benchmarks/internal/thread/worker.js @@ -1,12 +1,14 @@ 'use strict' const { isMainThread } = require('worker_threads') const { ThreadWorker } = require('../../../lib/index') -const { jsonIntegerSerialization } = require('../benchmark-utils') +const { WorkerFunctions, executeWorkerFunction } = require('../benchmark-utils') const debug = false function yourFunction (data) { - jsonIntegerSerialization(1000) + data = data || {} + data.function = data.function || WorkerFunctions.jsonIntegerSerialization + executeWorkerFunction(data) debug === true && console.debug('This is the main thread ' + isMainThread) return { ok: 1 } } diff --git a/tests/pools/cluster/dynamic.test.js b/tests/pools/cluster/dynamic.test.js index 6ce3d0a1..1e7fb870 100644 --- a/tests/pools/cluster/dynamic.test.js +++ b/tests/pools/cluster/dynamic.test.js @@ -1,6 +1,6 @@ const { expect } = require('expect') const { DynamicClusterPool } = require('../../../lib/index') -const WorkerFunctions = require('../../test-types') +const { WorkerFunctions } = require('../../test-types') const TestUtils = require('../../test-utils') describe('Dynamic cluster pool test suite', () => { diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index e9583741..4c36d8eb 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -1,6 +1,6 @@ const { expect } = require('expect') const { FixedClusterPool } = require('../../../lib/index') -const WorkerFunctions = require('../../test-types') +const { WorkerFunctions } = require('../../test-types') const TestUtils = require('../../test-utils') describe('Fixed cluster pool test suite', () => { diff --git a/tests/pools/thread/dynamic.test.js b/tests/pools/thread/dynamic.test.js index 8702dee8..9cd4e72c 100644 --- a/tests/pools/thread/dynamic.test.js +++ b/tests/pools/thread/dynamic.test.js @@ -1,6 +1,6 @@ const { expect } = require('expect') const { DynamicThreadPool } = require('../../../lib/index') -const WorkerFunctions = require('../../test-types') +const { WorkerFunctions } = require('../../test-types') const TestUtils = require('../../test-utils') describe('Dynamic thread pool test suite', () => { diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index c7abad00..01622f16 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -1,6 +1,6 @@ const { expect } = require('expect') const { FixedThreadPool } = require('../../../lib/index') -const WorkerFunctions = require('../../test-types') +const { WorkerFunctions } = require('../../test-types') const TestUtils = require('../../test-utils') describe('Fixed thread pool test suite', () => { diff --git a/tests/test-types.js b/tests/test-types.js index 01240310..91380343 100644 --- a/tests/test-types.js +++ b/tests/test-types.js @@ -4,4 +4,4 @@ const WorkerFunctions = { factorial: 'factorial' } -module.exports = WorkerFunctions +module.exports = { WorkerFunctions } diff --git a/tests/test-utils.js b/tests/test-utils.js index 31a33c62..78218e26 100644 --- a/tests/test-utils.js +++ b/tests/test-utils.js @@ -1,4 +1,4 @@ -const WorkerFunctions = require('./test-types') +const { WorkerFunctions } = require('./test-types') class TestUtils { static async waitExits (pool, numberOfExitEventsToWait) { diff --git a/tests/worker-files/cluster/testWorker.js b/tests/worker-files/cluster/testWorker.js index 456da63b..4c31e3ad 100644 --- a/tests/worker-files/cluster/testWorker.js +++ b/tests/worker-files/cluster/testWorker.js @@ -2,7 +2,7 @@ const { ClusterWorker, KillBehaviors } = require('../../../lib/index') const { isMaster } = require('cluster') const TestUtils = require('../../test-utils') -const WorkerFunctions = require('../../test-types') +const { WorkerFunctions } = require('../../test-types') function test (data) { data = data || {} diff --git a/tests/worker-files/thread/testWorker.js b/tests/worker-files/thread/testWorker.js index e6bc434b..f843329f 100644 --- a/tests/worker-files/thread/testWorker.js +++ b/tests/worker-files/thread/testWorker.js @@ -2,7 +2,7 @@ const { ThreadWorker, KillBehaviors } = require('../../../lib/index') const { isMainThread } = require('worker_threads') const TestUtils = require('../../test-utils') -const WorkerFunctions = require('../../test-types') +const { WorkerFunctions } = require('../../test-types') function test (data) { data = data || {}