From 1655b92eb1223501125f6cac2f83fc86fbc958ab Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 5 Jul 2023 19:13:02 +0200 Subject: [PATCH] refactor: use Set() instead of array in benchmarking code MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../dynamic-node-worker-threads-pool.mjs | 4 +- .../versus-external-pools/dynamic-piscina.mjs | 4 +- .../dynamic-poolifier.mjs | 4 +- .../dynamic-tinypool.mjs | 4 +- .../dynamic-worker-nodes.js | 4 +- .../dynamic-workerpool.mjs | 4 +- .../versus-external-pools/fixed-piscina.mjs | 4 +- .../versus-external-pools/fixed-poolifier.mjs | 4 +- .../versus-external-pools/fixed-tinypool.mjs | 4 +- .../fixed-worker-nodes.js | 4 +- .../fixed-workerpool.mjs | 4 +- .../static-node-worker-threads-pool.mjs | 4 +- package.json | 2 +- pnpm-lock.yaml | 44 +++++++++---------- 14 files changed, 47 insertions(+), 47 deletions(-) diff --git a/benchmarks/versus-external-pools/dynamic-node-worker-threads-pool.mjs b/benchmarks/versus-external-pools/dynamic-node-worker-threads-pool.mjs index 20404974..fcb1d84c 100644 --- a/benchmarks/versus-external-pools/dynamic-node-worker-threads-pool.mjs +++ b/benchmarks/versus-external-pools/dynamic-node-worker-threads-pool.mjs @@ -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, diff --git a/benchmarks/versus-external-pools/dynamic-piscina.mjs b/benchmarks/versus-external-pools/dynamic-piscina.mjs index a1e425f8..ddda47e7 100644 --- a/benchmarks/versus-external-pools/dynamic-piscina.mjs +++ b/benchmarks/versus-external-pools/dynamic-piscina.mjs @@ -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 diff --git a/benchmarks/versus-external-pools/dynamic-poolifier.mjs b/benchmarks/versus-external-pools/dynamic-poolifier.mjs index 48d3028f..ab527ee9 100644 --- a/benchmarks/versus-external-pools/dynamic-poolifier.mjs +++ b/benchmarks/versus-external-pools/dynamic-poolifier.mjs @@ -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 diff --git a/benchmarks/versus-external-pools/dynamic-tinypool.mjs b/benchmarks/versus-external-pools/dynamic-tinypool.mjs index acb8627f..c1de3772 100644 --- a/benchmarks/versus-external-pools/dynamic-tinypool.mjs +++ b/benchmarks/versus-external-pools/dynamic-tinypool.mjs @@ -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 diff --git a/benchmarks/versus-external-pools/dynamic-worker-nodes.js b/benchmarks/versus-external-pools/dynamic-worker-nodes.js index 17255ba2..7a77d882 100644 --- a/benchmarks/versus-external-pools/dynamic-worker-nodes.js +++ b/benchmarks/versus-external-pools/dynamic-worker-nodes.js @@ -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 diff --git a/benchmarks/versus-external-pools/dynamic-workerpool.mjs b/benchmarks/versus-external-pools/dynamic-workerpool.mjs index 9dc0e702..2fb02d4b 100644 --- a/benchmarks/versus-external-pools/dynamic-workerpool.mjs +++ b/benchmarks/versus-external-pools/dynamic-workerpool.mjs @@ -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 diff --git a/benchmarks/versus-external-pools/fixed-piscina.mjs b/benchmarks/versus-external-pools/fixed-piscina.mjs index f13b996a..5fe01b62 100644 --- a/benchmarks/versus-external-pools/fixed-piscina.mjs +++ b/benchmarks/versus-external-pools/fixed-piscina.mjs @@ -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 diff --git a/benchmarks/versus-external-pools/fixed-poolifier.mjs b/benchmarks/versus-external-pools/fixed-poolifier.mjs index aa922be8..91fc4027 100644 --- a/benchmarks/versus-external-pools/fixed-poolifier.mjs +++ b/benchmarks/versus-external-pools/fixed-poolifier.mjs @@ -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 diff --git a/benchmarks/versus-external-pools/fixed-tinypool.mjs b/benchmarks/versus-external-pools/fixed-tinypool.mjs index 9889a756..07b3abe8 100644 --- a/benchmarks/versus-external-pools/fixed-tinypool.mjs +++ b/benchmarks/versus-external-pools/fixed-tinypool.mjs @@ -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 diff --git a/benchmarks/versus-external-pools/fixed-worker-nodes.js b/benchmarks/versus-external-pools/fixed-worker-nodes.js index e70e61c8..d5b01353 100644 --- a/benchmarks/versus-external-pools/fixed-worker-nodes.js +++ b/benchmarks/versus-external-pools/fixed-worker-nodes.js @@ -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 diff --git a/benchmarks/versus-external-pools/fixed-workerpool.mjs b/benchmarks/versus-external-pools/fixed-workerpool.mjs index c5529194..6e11c145 100644 --- a/benchmarks/versus-external-pools/fixed-workerpool.mjs +++ b/benchmarks/versus-external-pools/fixed-workerpool.mjs @@ -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 diff --git a/benchmarks/versus-external-pools/static-node-worker-threads-pool.mjs b/benchmarks/versus-external-pools/static-node-worker-threads-pool.mjs index b8a90ea3..3632216b 100644 --- a/benchmarks/versus-external-pools/static-node-worker-threads-pool.mjs +++ b/benchmarks/versus-external-pools/static-node-worker-threads-pool.mjs @@ -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 diff --git a/package.json b/package.json index 02d47d0e..2f39ab9c 100644 --- a/package.json +++ b/package.json @@ -130,7 +130,7 @@ "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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 05a01f43..f8ba4194 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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 -- 2.34.1