From: Jérôme Benoit Date: Mon, 17 Oct 2022 22:51:55 +0000 (+0200) Subject: Factor out benchmarks helpers X-Git-Tag: v2.3.5~16 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=d1a9aa414b60e38c91f5623f3572dc46c50f5f14;hp=8c97ee641800a73d02516dad3e6b5172ec477e2d;p=poolifier.git Factor out benchmarks helpers Signed-off-by: Jérôme Benoit --- diff --git a/benchmarks/internal/benchmark-utils.js b/benchmarks/benchmarks-utils.js similarity index 92% rename from benchmarks/internal/benchmark-utils.js rename to benchmarks/benchmarks-utils.js index 8ea43599..4e3cdc9c 100644 --- a/benchmarks/internal/benchmark-utils.js +++ b/benchmarks/benchmarks-utils.js @@ -71,11 +71,11 @@ function factorial (n) { function executeWorkerFunction (data) { switch (data.function) { case WorkerFunctions.jsonIntegerSerialization: - return jsonIntegerSerialization(data.n || 1000) + return jsonIntegerSerialization(data.taskSize || 1000) case WorkerFunctions.fibonacci: - return fibonacci(data.n || 1000) + return fibonacci(data.taskSize || 1000) case WorkerFunctions.factorial: - return factorial(data.n || 1000) + return factorial(data.taskSize || 1000) default: throw new Error('Unknown worker function') } diff --git a/benchmarks/internal/bench.js b/benchmarks/internal/bench.js index 7d33fcc5..f9425955 100644 --- a/benchmarks/internal/bench.js +++ b/benchmarks/internal/bench.js @@ -23,7 +23,7 @@ const { fixedThreadTestLessRecentlyUsed, fixedThreadTestWeightedRoundRobin } = require('./thread/fixed') -const { LIST_FORMATTER } = require('./benchmark-utils') +const { LIST_FORMATTER } = require('../benchmarks-utils') const suite = new Benchmark.Suite('poolifier') diff --git a/benchmarks/internal/choose-worker.js b/benchmarks/internal/choose-worker.js index 560a395b..7cf3029f 100644 --- a/benchmarks/internal/choose-worker.js +++ b/benchmarks/internal/choose-worker.js @@ -1,5 +1,5 @@ const Benchmark = require('benchmark') -const { LIST_FORMATTER } = require('./benchmark-utils') +const { LIST_FORMATTER } = require('../benchmarks-utils') const suite = new Benchmark.Suite() diff --git a/benchmarks/internal/cluster/dynamic.js b/benchmarks/internal/cluster/dynamic.js index dc0f7cf3..105bbdaa 100644 --- a/benchmarks/internal/cluster/dynamic.js +++ b/benchmarks/internal/cluster/dynamic.js @@ -2,7 +2,7 @@ const { DynamicClusterPool, WorkerChoiceStrategies } = require('../../../lib/index') -const { runPoolifierTest } = require('../benchmark-utils') +const { runPoolifierTest } = require('../../benchmarks-utils') const size = 30 const numberOfTasks = 1 diff --git a/benchmarks/internal/cluster/fixed.js b/benchmarks/internal/cluster/fixed.js index 388689a3..da691aa9 100644 --- a/benchmarks/internal/cluster/fixed.js +++ b/benchmarks/internal/cluster/fixed.js @@ -2,7 +2,7 @@ const { FixedClusterPool, WorkerChoiceStrategies } = require('../../../lib/index') -const { runPoolifierTest } = require('../benchmark-utils') +const { runPoolifierTest } = require('../../benchmarks-utils') const size = 30 const numberOfTasks = 1 diff --git a/benchmarks/internal/cluster/worker.js b/benchmarks/internal/cluster/worker.js index 29005f9c..c64363de 100644 --- a/benchmarks/internal/cluster/worker.js +++ b/benchmarks/internal/cluster/worker.js @@ -1,7 +1,10 @@ 'use strict' const { isMaster } = require('cluster') const { ClusterWorker } = require('../../../lib/index') -const { WorkerFunctions, executeWorkerFunction } = require('../benchmark-utils') +const { + WorkerFunctions, + executeWorkerFunction +} = require('../../benchmarks-utils') const debug = false diff --git a/benchmarks/internal/quick-select.js b/benchmarks/internal/quick-select.js index cf8f2354..74b09c9f 100644 --- a/benchmarks/internal/quick-select.js +++ b/benchmarks/internal/quick-select.js @@ -1,5 +1,5 @@ const Benchmark = require('benchmark') -const { generateRandomInteger, LIST_FORMATTER } = require('./benchmark-utils') +const { generateRandomInteger, LIST_FORMATTER } = require('../benchmarks-utils') const suite = new Benchmark.Suite() diff --git a/benchmarks/internal/thread/dynamic.js b/benchmarks/internal/thread/dynamic.js index a4185453..fa2e0f83 100644 --- a/benchmarks/internal/thread/dynamic.js +++ b/benchmarks/internal/thread/dynamic.js @@ -2,7 +2,7 @@ const { DynamicThreadPool, WorkerChoiceStrategies } = require('../../../lib/index') -const { runPoolifierTest } = require('../benchmark-utils') +const { runPoolifierTest } = require('../../benchmarks-utils') const size = 30 const numberOfTasks = 1 diff --git a/benchmarks/internal/thread/fixed.js b/benchmarks/internal/thread/fixed.js index 37635237..3f40f3fb 100644 --- a/benchmarks/internal/thread/fixed.js +++ b/benchmarks/internal/thread/fixed.js @@ -2,7 +2,7 @@ const { FixedThreadPool, WorkerChoiceStrategies } = require('../../../lib/index') -const { runPoolifierTest } = require('../benchmark-utils') +const { runPoolifierTest } = require('../../benchmarks-utils') const size = 30 const numberOfTasks = 1 diff --git a/benchmarks/internal/thread/worker.js b/benchmarks/internal/thread/worker.js index 902cecc1..e84711ce 100644 --- a/benchmarks/internal/thread/worker.js +++ b/benchmarks/internal/thread/worker.js @@ -1,7 +1,10 @@ 'use strict' const { isMainThread } = require('worker_threads') const { ThreadWorker } = require('../../../lib/index') -const { WorkerFunctions, executeWorkerFunction } = require('../benchmark-utils') +const { + WorkerFunctions, + executeWorkerFunction +} = require('../../benchmarks-utils') const debug = false diff --git a/benchmarks/versus-external-pools/functions/function-to-bench.js b/benchmarks/versus-external-pools/functions/function-to-bench.js index b3e19fe9..bbc17c18 100644 --- a/benchmarks/versus-external-pools/functions/function-to-bench.js +++ b/benchmarks/versus-external-pools/functions/function-to-bench.js @@ -1,4 +1,9 @@ const fs = require('fs') +const { + WorkerFunctions, + executeWorkerFunction + // eslint-disable-next-line node/no-unpublished-require +} = require('../../benchmarks-utils') const TaskTypes = { CPU_INTENSIVE: 'CPU_INTENSIVE', @@ -13,12 +18,8 @@ module.exports = function (data) { switch (data.taskType) { case TaskTypes.CPU_INTENSIVE: // CPU intensive task - for (let i = 0; i < data.taskSize; i++) { - const o = { - a: i - } - JSON.stringify(o) - } + data.function = data.function || WorkerFunctions.jsonIntegerSerialization + executeWorkerFunction(data) return { ok: 1 } case TaskTypes.IO_INTENSIVE: // IO intensive task