Factor out benchmarks helpers
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 17 Oct 2022 22:51:55 +0000 (00:51 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 17 Oct 2022 22:51:55 +0000 (00:51 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
benchmarks/benchmarks-utils.js [moved from benchmarks/internal/benchmark-utils.js with 92% similarity]
benchmarks/internal/bench.js
benchmarks/internal/choose-worker.js
benchmarks/internal/cluster/dynamic.js
benchmarks/internal/cluster/fixed.js
benchmarks/internal/cluster/worker.js
benchmarks/internal/quick-select.js
benchmarks/internal/thread/dynamic.js
benchmarks/internal/thread/fixed.js
benchmarks/internal/thread/worker.js
benchmarks/versus-external-pools/functions/function-to-bench.js

similarity index 92%
rename from benchmarks/internal/benchmark-utils.js
rename to benchmarks/benchmarks-utils.js
index 8ea43599282949a246d684dcf483a07c68377568..4e3cdc9c3af590c7e9812bf80abd81d3743155e8 100644 (file)
@@ -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')
   }
index 7d33fcc5dcb58489bf645cac7a55902353012801..f942595565fde1d5f749bbade274b53e947bd9b4 100644 (file)
@@ -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')
 
index 560a395b69207ec6fede5d6abf39e3a2ad4ba2f3..7cf3029ff2aa007e22f60bc5c52fab970393ca90 100644 (file)
@@ -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()
 
index dc0f7cf3493e3b94c271270d6c350dfbabb07706..105bbdaa9d77eef540cfa361e6d794095b400363 100644 (file)
@@ -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
index 388689a3be7e5bc8ba37e38e7b53cd1b902f0d22..da691aa9237a387d1b6d2cfe4ffe01d64cf506f9 100644 (file)
@@ -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
index 29005f9c219bc9b932317d291dc8f059a2819d47..c64363de937c233972405e9473e7ddab80f5294b 100644 (file)
@@ -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
 
index cf8f23540d31add705554d9ccb71ac4b3339e0ca..74b09c9f642d527570b257ce45e8471560cf3b28 100644 (file)
@@ -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()
 
index a418545362744580dc3b00556faaa9ee40007d44..fa2e0f83bf56c4cf4eaf62814c32e46b8206af94 100644 (file)
@@ -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
index 376352376d4bbb3f4636d2dc4baca2cdeaf91ba2..3f40f3fbcac920f9f4013bdb59d3c155fdb42b57 100644 (file)
@@ -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
index 902cecc10c3b22c209d689f5df853b6705e669b2..e84711ce6d024466d299f21093c7a4d518ca34f2 100644 (file)
@@ -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
 
index b3e19fe95f81c76edec864b47812a4408b729a6c..bbc17c18da0cdc29f59da0e2652cb8daaea452e7 100644 (file)
@@ -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