refactor: use Set() instead of array in benchmarking code
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 5 Jul 2023 17:13:02 +0000 (19:13 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 5 Jul 2023 17:13:02 +0000 (19:13 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
14 files changed:
benchmarks/versus-external-pools/dynamic-node-worker-threads-pool.mjs
benchmarks/versus-external-pools/dynamic-piscina.mjs
benchmarks/versus-external-pools/dynamic-poolifier.mjs
benchmarks/versus-external-pools/dynamic-tinypool.mjs
benchmarks/versus-external-pools/dynamic-worker-nodes.js
benchmarks/versus-external-pools/dynamic-workerpool.mjs
benchmarks/versus-external-pools/fixed-piscina.mjs
benchmarks/versus-external-pools/fixed-poolifier.mjs
benchmarks/versus-external-pools/fixed-tinypool.mjs
benchmarks/versus-external-pools/fixed-worker-nodes.js
benchmarks/versus-external-pools/fixed-workerpool.mjs
benchmarks/versus-external-pools/static-node-worker-threads-pool.mjs
package.json
pnpm-lock.yaml

index 204049749d2e171a1cb067ec550179cf65a124fa..fcb1d84c29ee43bcb5c615418d98cfe3819b84ad 100644 (file)
@@ -15,9 +15,9 @@ const data = {
 const pool = new DynamicPool(size)
 
 async function run () {
-  const promises = []
+  const promises = new Set()
   for (let i = 0; i < iterations; i++) {
-    promises.push(
+    promises.add(
       pool.exec({
         task: functionToBench,
         param: data,
index a1e425f8e95f3a19c8cc5d776cb225fd11f9b200..ddda47e75138f6157b973af4049d382f497a397f 100644 (file)
@@ -17,9 +17,9 @@ const piscina = new Piscina({
 })
 
 async function run () {
-  const promises = []
+  const promises = new Set()
   for (let i = 0; i < iterations; i++) {
-    promises.push(piscina.run(data))
+    promises.add(piscina.run(data))
   }
   await Promise.all(promises)
   // eslint-disable-next-line n/no-process-exit
index 48d3028fb1a1cbd399f608b6d9e956abce3399e0..ab527ee90bb4c0a946138853fa2b19793d24c5e4 100644 (file)
@@ -16,9 +16,9 @@ const dynamicPool = new DynamicThreadPool(
 )
 
 async function run () {
-  const promises = []
+  const promises = new Set()
   for (let i = 0; i < iterations; i++) {
-    promises.push(dynamicPool.execute(data))
+    promises.add(dynamicPool.execute(data))
   }
   await Promise.all(promises)
   // eslint-disable-next-line n/no-process-exit
index acb8627f4f1e2f4ca1592d8aaa29b9f21a6d6160..c1de377230add86db85da551bfb98d2558957bcd 100644 (file)
@@ -17,9 +17,9 @@ const tinypool = new Tinypool({
 })
 
 async function run () {
-  const promises = []
+  const promises = new Set()
   for (let i = 0; i < iterations; i++) {
-    promises.push(tinypool.run(data))
+    promises.add(tinypool.run(data))
   }
   await Promise.all(promises)
   // eslint-disable-next-line n/no-process-exit
index 17255ba2dc2455414a791999233e32e3579a3414..7a77d88278877f1acdcc037b8cd55717c76759ee 100644 (file)
@@ -20,9 +20,9 @@ const workerNodes = new WorkerNodes(
 )
 
 async function run () {
-  const promises = []
+  const promises = new Set()
   for (let i = 0; i < iterations; i++) {
-    promises.push(workerNodes.call.functionToBench(data))
+    promises.add(workerNodes.call.functionToBench(data))
   }
   await Promise.all(promises)
   // eslint-disable-next-line n/no-process-exit
index 9dc0e70275ca98f89da39b498bebfb4bce70b273..2fb02d4b5e7c2b37b3beb592f8a5adf550bd42e9 100644 (file)
@@ -19,9 +19,9 @@ const workerPool = workerpool.pool(
 )
 
 async function run () {
-  const promises = []
+  const promises = new Set()
   for (let i = 0; i < iterations; i++) {
-    promises.push(workerPool.exec('functionToBench', dataArray))
+    promises.add(workerPool.exec('functionToBench', dataArray))
   }
   await Promise.all(promises)
   // eslint-disable-next-line n/no-process-exit
index f13b996a7aead8e3a2eeeecfee16cf06a59407de..5fe01b62aa4816e7a5a1e14bc6348d1facd5acfd 100644 (file)
@@ -17,9 +17,9 @@ const piscina = new Piscina({
 })
 
 async function run () {
-  const promises = []
+  const promises = new Set()
   for (let i = 0; i < iterations; i++) {
-    promises.push(piscina.run(data))
+    promises.add(piscina.run(data))
   }
   await Promise.all(promises)
   // eslint-disable-next-line n/no-process-exit
index aa922be8a9928651519572177eeb728cb9fe72b3..91fc4027e5eb468174511b9018687fdff9417831 100644 (file)
@@ -15,9 +15,9 @@ const fixedPool = new FixedThreadPool(
 )
 
 async function run () {
-  const promises = []
+  const promises = new Set()
   for (let i = 0; i < iterations; i++) {
-    promises.push(fixedPool.execute(data))
+    promises.add(fixedPool.execute(data))
   }
   await Promise.all(promises)
   // eslint-disable-next-line n/no-process-exit
index 9889a75667547dc4395ff274e6f574ad6d6b98d3..07b3abe84a2cd258c26e2d4b3bc9f85bfd4f96ee 100644 (file)
@@ -17,9 +17,9 @@ const tinypool = new Tinypool({
 })
 
 async function run () {
-  const promises = []
+  const promises = new Set()
   for (let i = 0; i < iterations; i++) {
-    promises.push(tinypool.run(data))
+    promises.add(tinypool.run(data))
   }
   await Promise.all(promises)
   // eslint-disable-next-line n/no-process-exit
index e70e61c8a0b8861644440fc6358be0d6f42ab445..d5b01353d2eb0a9c54272e9619080bec92d7bebb 100644 (file)
@@ -20,9 +20,9 @@ const workerNodes = new WorkerNodes(
 )
 
 async function run () {
-  const promises = []
+  const promises = new Set()
   for (let i = 0; i < iterations; i++) {
-    promises.push(workerNodes.call.functionToBench(data))
+    promises.add(workerNodes.call.functionToBench(data))
   }
   await Promise.all(promises)
   // eslint-disable-next-line n/no-process-exit
index c55291945515e0bb0391db472e5ea5e5e3c16547..6e11c1454f69e3edf10cadc561c621498334be34 100644 (file)
@@ -19,9 +19,9 @@ const workerPool = workerpool.pool(
 )
 
 async function run () {
-  const promises = []
+  const promises = new Set()
   for (let i = 0; i < iterations; i++) {
-    promises.push(workerPool.exec('functionToBench', dataArray))
+    promises.add(workerPool.exec('functionToBench', dataArray))
   }
   await Promise.all(promises)
   // eslint-disable-next-line n/no-process-exit
index b8a90ea321ccae3cf912b010ce8d4d21b30a7a53..3632216b5daeed0771077f873bbf9bca5e69f177 100644 (file)
@@ -18,9 +18,9 @@ const pool = new StaticPool({
 })
 
 async function run () {
-  const promises = []
+  const promises = new Set()
   for (let i = 0; i < iterations; i++) {
-    promises.push(pool.exec(data))
+    promises.add(pool.exec(data))
   }
   await Promise.all(promises)
   // eslint-disable-next-line n/no-process-exit
index 02d47d0e21a6b209f702550294936c6df743fff9..2f39ab9c32c59003ebd6efecb376d92758aca6fc 100644 (file)
     "mochawesome": "^7.1.3",
     "prettier": "^2.8.8",
     "release-it": "^15.11.0",
-    "rollup": "^3.26.0",
+    "rollup": "^3.26.1",
     "rollup-plugin-analyzer": "^4.0.0",
     "rollup-plugin-command": "^1.1.3",
     "rollup-plugin-delete": "^2.0.0",
index 05a01f4319bd97cefcb9e285e8382497c7f7b79a..f8ba41945a22ef1bc126eab0377cb0385b8da1e0 100644 (file)
@@ -19,10 +19,10 @@ devDependencies:
     version: 3.1.0(release-it@15.11.0)
   '@rollup/plugin-terser':
     specifier: ^0.4.3
-    version: 0.4.3(rollup@3.26.0)
+    version: 0.4.3(rollup@3.26.1)
   '@rollup/plugin-typescript':
     specifier: ^11.1.2
-    version: 11.1.2(rollup@3.26.0)(typescript@5.1.6)
+    version: 11.1.2(rollup@3.26.1)(typescript@5.1.6)
   '@types/node':
     specifier: ^20.3.3
     version: 20.3.3
@@ -96,8 +96,8 @@ devDependencies:
     specifier: ^15.11.0
     version: 15.11.0
   rollup:
-    specifier: ^3.26.0
-    version: 3.26.0
+    specifier: ^3.26.1
+    version: 3.26.1
   rollup-plugin-analyzer:
     specifier: ^4.0.0
     version: 4.0.0
@@ -733,7 +733,7 @@ packages:
       string-template: 1.0.0
     dev: true
 
-  /@rollup/plugin-terser@0.4.3(rollup@3.26.0):
+  /@rollup/plugin-terser@0.4.3(rollup@3.26.1):
     resolution: {integrity: sha512-EF0oejTMtkyhrkwCdg0HJ0IpkcaVg1MMSf2olHb2Jp+1mnLM04OhjpJWGma4HobiDTF0WCyViWuvadyE9ch2XA==}
     engines: {node: '>=14.0.0'}
     peerDependencies:
@@ -742,13 +742,13 @@ packages:
       rollup:
         optional: true
     dependencies:
-      rollup: 3.26.0
+      rollup: 3.26.1
       serialize-javascript: 6.0.1
       smob: 1.4.0
       terser: 5.18.2
     dev: true
 
-  /@rollup/plugin-typescript@11.1.2(rollup@3.26.0)(typescript@5.1.6):
+  /@rollup/plugin-typescript@11.1.2(rollup@3.26.1)(typescript@5.1.6):
     resolution: {integrity: sha512-0ghSOCMcA7fl1JM+0gYRf+Q/HWyg+zg7/gDSc+fRLmlJWcW5K1I+CLRzaRhXf4Y3DRyPnnDo4M2ktw+a6JcDEg==}
     engines: {node: '>=14.0.0'}
     peerDependencies:
@@ -761,13 +761,13 @@ packages:
       tslib:
         optional: true
     dependencies:
-      '@rollup/pluginutils': 5.0.2(rollup@3.26.0)
+      '@rollup/pluginutils': 5.0.2(rollup@3.26.1)
       resolve: 1.22.2
-      rollup: 3.26.0
+      rollup: 3.26.1
       typescript: 5.1.6
     dev: true
 
-  /@rollup/pluginutils@5.0.2(rollup@3.26.0):
+  /@rollup/pluginutils@5.0.2(rollup@3.26.1):
     resolution: {integrity: sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==}
     engines: {node: '>=14.0.0'}
     peerDependencies:
@@ -779,7 +779,7 @@ packages:
       '@types/estree': 1.0.1
       estree-walker: 2.0.2
       picomatch: 2.3.1
-      rollup: 3.26.0
+      rollup: 3.26.1
     dev: true
 
   /@sinclair/typebox@0.27.8:
@@ -1055,12 +1055,12 @@ packages:
       through: 2.3.8
     dev: true
 
-  /acorn-jsx@5.3.2(acorn@8.9.0):
+  /acorn-jsx@5.3.2(acorn@8.10.0):
     resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==}
     peerDependencies:
       acorn: ^6.0.0 || ^7.0.0 || ^8.0.0
     dependencies:
-      acorn: 8.9.0
+      acorn: 8.10.0
     dev: true
 
   /acorn-walk@8.2.0:
@@ -1068,8 +1068,8 @@ packages:
     engines: {node: '>=0.4.0'}
     dev: true
 
-  /acorn@8.9.0:
-    resolution: {integrity: sha512-jaVNAFBHNLXspO543WnNNPZFRtavh3skAkITqD0/2aeMkKZTN+254PyhwxFYrk3vQ1xfY+2wbesJMs/JC8/PwQ==}
+  /acorn@8.10.0:
+    resolution: {integrity: sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==}
     engines: {node: '>=0.4.0'}
     hasBin: true
     dev: true
@@ -2579,8 +2579,8 @@ packages:
     resolution: {integrity: sha512-1FH/IiruXZ84tpUlm0aCUEwMl2Ho5ilqVh0VvQXw+byAz/4SAciyHLlfmL5WYqsvD38oymdUwBss0LtK8m4s/A==}
     engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
     dependencies:
-      acorn: 8.9.0
-      acorn-jsx: 5.3.2(acorn@8.9.0)
+      acorn: 8.10.0
+      acorn-jsx: 5.3.2(acorn@8.10.0)
       eslint-visitor-keys: 3.4.1
     dev: true
 
@@ -5190,8 +5190,8 @@ packages:
       del: 5.1.0
     dev: true
 
-  /rollup@3.26.0:
-    resolution: {integrity: sha512-YzJH0eunH2hr3knvF3i6IkLO/jTjAEwU4HoMUbQl4//Tnl3ou0e7P5SjxdDr8HQJdeUJShlbEHXrrnEHy1l7Yg==}
+  /rollup@3.26.1:
+    resolution: {integrity: sha512-I5gJCSpSMr3U9wv4D5YA8g7w7cj3eaSDeo7t+JcaFQOmoOUBgu4K9iMp8k3EZnwbJrjQxUMSKxMyB8qEQzzaSg==}
     engines: {node: '>=14.18.0', npm: '>=8.0.0'}
     hasBin: true
     optionalDependencies:
@@ -5652,7 +5652,7 @@ packages:
     hasBin: true
     dependencies:
       '@jridgewell/source-map': 0.3.5
-      acorn: 8.9.0
+      acorn: 8.10.0
       commander: 2.20.3
       source-map-support: 0.5.21
     dev: true
@@ -5733,7 +5733,7 @@ packages:
       '@tsconfig/node14': 1.0.3
       '@tsconfig/node16': 1.0.4
       '@types/node': 20.3.3
-      acorn: 8.9.0
+      acorn: 8.10.0
       acorn-walk: 8.2.0
       arg: 4.1.3
       create-require: 1.1.1
@@ -5995,7 +5995,7 @@ packages:
     engines: {node: '>=6.0'}
     hasBin: true
     dependencies:
-      acorn: 8.9.0
+      acorn: 8.10.0
       acorn-walk: 8.2.0
     dev: true