Enchance benchmarking code
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 10 Oct 2022 20:44:13 +0000 (22:44 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 10 Oct 2022 20:44:13 +0000 (22:44 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
13 files changed:
.github/dependabot.yml
.lintstagedrc.js
benchmarks/internal/benchmark-utils.js
benchmarks/internal/cluster/worker.js
benchmarks/internal/thread/worker.js
tests/pools/cluster/dynamic.test.js
tests/pools/cluster/fixed.test.js
tests/pools/thread/dynamic.test.js
tests/pools/thread/fixed.test.js
tests/test-types.js
tests/test-utils.js
tests/worker-files/cluster/testWorker.js
tests/worker-files/thread/testWorker.js

index b4edbf736845c387e345dd8d08dfa62d775cac7b..cd90cc537b1478180f034dd940d57cb7022b3bfc 100644 (file)
@@ -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
index 433ce7f0c53fd6067b09fb3c6e8c4bf92e08b28b..67f3a844791f05bfc29931d6adee61aa299a3d65 100644 (file)
@@ -1,7 +1,7 @@
 module.exports = {
   '**/*.{js,mjs,ts}': ['eslint --cache --fix'],
   '**/*.{json,md,yml}': [
-    'prettier --loglevel silent --write',
+    'prettier --write',
     'prettierx --write'
   ]
 }
index 7cb4e54f500283d5c5da6e69b743f5b851ba344e..a7e4ddecded212d3f226af05d44e0a5d47441cf9 100644 (file)
@@ -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
 }
index 0235afface236f2e2492e669636d74df37770c81..29005f9c219bc9b932317d291dc8f059a2819d47 100644 (file)
@@ -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 }
 }
index 5196ca38c9758e24120a2ac45576cbdc49d26d12..902cecc10c3b22c209d689f5df853b6705e669b2 100644 (file)
@@ -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 }
 }
index 6ce3d0a1ef978bd138a4fd8d0eb38ed596366edb..1e7fb8703f9a026e0abde5048e25468abef14a43 100644 (file)
@@ -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', () => {
index e958374139bc560167bc61c420a278394283a7ef..4c36d8eb8e55f9666d59ea10122a2a77061eb7c5 100644 (file)
@@ -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', () => {
index 8702dee8383ad7b5ec5a41dae567bfa8049105e3..9cd4e72c57b1098256b9c2f356fcfc0ded6da730 100644 (file)
@@ -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', () => {
index c7abad00834c0a6cfd3c96bf4ae06b731d82e2f3..01622f1622c87237e1dc501313ff14ef348cc2dd 100644 (file)
@@ -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', () => {
index 012403107012246660e7ebe04af5b463c584d70d..913803437597b46556f26e5dae46159b16dc7627 100644 (file)
@@ -4,4 +4,4 @@ const WorkerFunctions = {
   factorial: 'factorial'
 }
 
-module.exports = WorkerFunctions
+module.exports = { WorkerFunctions }
index 31a33c627eec12c671872e3e2acf8c89d6bfe34c..78218e2668c34bbfef44e680e1e9676eccf7b7cd 100644 (file)
@@ -1,4 +1,4 @@
-const WorkerFunctions = require('./test-types')
+const { WorkerFunctions } = require('./test-types')
 
 class TestUtils {
   static async waitExits (pool, numberOfExitEventsToWait) {
index 456da63b7bc60348711df9d1cad3323f22928cce..4c31e3ad9125decdd56b103e9f80f35531325ec3 100644 (file)
@@ -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 || {}
index e6bc434b7df633e501ea1fcf43586451db75fd14..f843329f296b17ae295eb3c58beeeb284b3e3b71 100644 (file)
@@ -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 || {}