From 8fca928868a8f73a16d5d990dda9a4480ea28ab5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 25 Jun 2023 15:03:57 +0200 Subject: [PATCH] refactor: convert benchmarks code to ESM MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../versus-external-pools/BENCH-100000.md | 17 ----------- ...s => dynamic-node-worker-threads-pool.mjs} | 6 ++-- ...dynamic-piscina.js => dynamic-piscina.mjs} | 6 ++-- ...mic-poolifier.js => dynamic-poolifier.mjs} | 6 ++-- .../dynamic-tinypool.mjs | 4 +-- ...rker-nodes.js => dynamic-worker-nodes.mjs} | 7 +++-- ...c-workerpool.js => dynamic-workerpool.mjs} | 6 ++-- .../{fixed-microjob.js => fixed-microjob.mjs} | 6 ++-- .../{fixed-piscina.js => fixed-piscina.mjs} | 6 ++-- ...fixed-poolifier.js => fixed-poolifier.mjs} | 6 ++-- ...xed-threadwork.js => fixed-threadwork.mjs} | 4 +-- .../versus-external-pools/fixed-tinypool.mjs | 4 +-- ...worker-nodes.js => fixed-worker-nodes.mjs} | 7 +++-- ...xed-workerpool.js => fixed-workerpool.mjs} | 6 ++-- ...tion-to-bench.js => function-to-bench.mjs} | 9 +++--- .../hyperfine_benchmarks.sh | 28 +++++++++---------- .../versus-external-pools/pool-threadwork.js | 9 ------ .../versus-external-pools/pool-threadwork.mjs | 9 ++++++ ...js => static-node-worker-threads-pool.mjs} | 6 ++-- .../{threadjs.js => threadjs.mjs} | 6 ++-- .../piscina/function-to-bench-worker.js | 3 -- .../piscina/function-to-bench-worker.mjs | 2 ++ .../poolifier/function-to-bench-worker.js | 4 --- .../poolifier/function-to-bench-worker.mjs | 3 ++ .../threadjs/function-to-bench-worker.js | 9 ------ .../threadjs/function-to-bench-worker.mjs | 8 ++++++ .../tinypool/function-to-bench-worker.js | 3 -- .../tinypool/function-to-bench-worker.mjs | 2 ++ .../worker-nodes/function-to-bench-worker.js | 3 -- .../worker-nodes/function-to-bench-worker.mjs | 2 ++ ...worker.js => function-to-bench-worker.mjs} | 5 ++-- 31 files changed, 90 insertions(+), 112 deletions(-) rename benchmarks/versus-external-pools/{dynamic-node-worker-threads-pool.js => dynamic-node-worker-threads-pool.mjs} (83%) rename benchmarks/versus-external-pools/{dynamic-piscina.js => dynamic-piscina.mjs} (85%) rename benchmarks/versus-external-pools/{dynamic-poolifier.js => dynamic-poolifier.mjs} (83%) rename benchmarks/versus-external-pools/{dynamic-worker-nodes.js => dynamic-worker-nodes.mjs} (82%) rename benchmarks/versus-external-pools/{dynamic-workerpool.js => dynamic-workerpool.mjs} (85%) rename benchmarks/versus-external-pools/{fixed-microjob.js => fixed-microjob.mjs} (85%) rename benchmarks/versus-external-pools/{fixed-piscina.js => fixed-piscina.mjs} (85%) rename benchmarks/versus-external-pools/{fixed-poolifier.js => fixed-poolifier.mjs} (83%) rename benchmarks/versus-external-pools/{fixed-threadwork.js => fixed-threadwork.mjs} (89%) rename benchmarks/versus-external-pools/{fixed-worker-nodes.js => fixed-worker-nodes.mjs} (82%) rename benchmarks/versus-external-pools/{fixed-workerpool.js => fixed-workerpool.mjs} (85%) rename benchmarks/versus-external-pools/functions/{function-to-bench.js => function-to-bench.mjs} (91%) delete mode 100644 benchmarks/versus-external-pools/pool-threadwork.js create mode 100644 benchmarks/versus-external-pools/pool-threadwork.mjs rename benchmarks/versus-external-pools/{static-node-worker-threads-pool.js => static-node-worker-threads-pool.mjs} (82%) rename benchmarks/versus-external-pools/{threadjs.js => threadjs.mjs} (86%) delete mode 100644 benchmarks/versus-external-pools/workers/piscina/function-to-bench-worker.js create mode 100644 benchmarks/versus-external-pools/workers/piscina/function-to-bench-worker.mjs delete mode 100644 benchmarks/versus-external-pools/workers/poolifier/function-to-bench-worker.js create mode 100644 benchmarks/versus-external-pools/workers/poolifier/function-to-bench-worker.mjs delete mode 100644 benchmarks/versus-external-pools/workers/threadjs/function-to-bench-worker.js create mode 100644 benchmarks/versus-external-pools/workers/threadjs/function-to-bench-worker.mjs delete mode 100644 benchmarks/versus-external-pools/workers/tinypool/function-to-bench-worker.js create mode 100644 benchmarks/versus-external-pools/workers/tinypool/function-to-bench-worker.mjs delete mode 100644 benchmarks/versus-external-pools/workers/worker-nodes/function-to-bench-worker.js create mode 100644 benchmarks/versus-external-pools/workers/worker-nodes/function-to-bench-worker.mjs rename benchmarks/versus-external-pools/workers/workerpool/{function-to-bench-worker.js => function-to-bench-worker.mjs} (65%) diff --git a/benchmarks/versus-external-pools/BENCH-100000.md b/benchmarks/versus-external-pools/BENCH-100000.md index 6144bdb4..e69de29b 100644 --- a/benchmarks/versus-external-pools/BENCH-100000.md +++ b/benchmarks/versus-external-pools/BENCH-100000.md @@ -1,17 +0,0 @@ -| Command | Mean [s] | Min [s] | Max [s] | Relative | -| :----------------------------------------- | -------------: | ------: | ------: | ----------: | -| `node dynamic-poolifier.js` | 14.335 ± 0.244 | 14.080 | 15.133 | 1.02 ± 0.02 | -| `node fixed-poolifier.js` | 14.070 ± 0.229 | 13.783 | 14.640 | 1.00 | -| `node dynamic-piscina.js` | 15.119 ± 0.155 | 14.973 | 15.534 | 1.07 ± 0.02 | -| `node fixed-piscina.js` | 16.444 ± 0.314 | 16.219 | 17.152 | 1.17 ± 0.03 | -| `node fixed-tinypool.mjs` | 16.360 ± 0.301 | 16.129 | 17.051 | 1.16 ± 0.03 | -| `node dynamic-tinypool.mjs` | 15.319 ± 0.282 | 14.990 | 16.117 | 1.09 ± 0.03 | -| `node dynamic-workerpool.js` | 17.021 ± 0.416 | 16.663 | 18.025 | 1.21 ± 0.04 | -| `node fixed-workerpool.js` | 17.430 ± 0.281 | 17.190 | 18.235 | 1.24 ± 0.03 | -| `node dynamic-node-worker-threads-pool.js` | 25.111 ± 0.267 | 24.885 | 25.908 | 1.78 ± 0.03 | -| `node static-node-worker-threads-pool.js` | 16.958 ± 0.235 | 16.772 | 17.846 | 1.21 ± 0.03 | -| `node threadjs.js` | 47.460 ± 2.351 | 42.898 | 53.758 | 3.37 ± 0.18 | -| `node fixed-threadwork.js` | 16.492 ± 0.239 | 16.279 | 17.453 | 1.17 ± 0.03 | -| `node fixed-microjob.js` | 33.609 ± 0.571 | 33.100 | 35.256 | 2.39 ± 0.06 | -| `node dynamic-worker-nodes.js` | 16.087 ± 0.209 | 15.907 | 16.896 | 1.14 ± 0.02 | -| `node fixed-worker-nodes.js` | 16.680 ± 0.254 | 16.480 | 17.412 | 1.19 ± 0.03 | diff --git a/benchmarks/versus-external-pools/dynamic-node-worker-threads-pool.js b/benchmarks/versus-external-pools/dynamic-node-worker-threads-pool.mjs similarity index 83% rename from benchmarks/versus-external-pools/dynamic-node-worker-threads-pool.js rename to benchmarks/versus-external-pools/dynamic-node-worker-threads-pool.mjs index 0a56d1fd..743b01d6 100644 --- a/benchmarks/versus-external-pools/dynamic-node-worker-threads-pool.js +++ b/benchmarks/versus-external-pools/dynamic-node-worker-threads-pool.mjs @@ -1,8 +1,8 @@ // IMPORT LIBRARIES -const { DynamicPool } = require('node-worker-threads-pool') +import { DynamicPool } from 'node-worker-threads-pool' // FINISH IMPORT LIBRARIES // IMPORT FUNCTION TO BENCH -const functionToBench = require('./functions/function-to-bench') +import functionToBench from './functions/function-to-bench.mjs' // FINISH IMPORT FUNCTION TO BENCH const size = parseInt(process.env.POOL_SIZE) const iterations = parseInt(process.env.NUM_ITERATIONS) @@ -29,4 +29,4 @@ async function run () { process.exit() } -run() +await run() diff --git a/benchmarks/versus-external-pools/dynamic-piscina.js b/benchmarks/versus-external-pools/dynamic-piscina.mjs similarity index 85% rename from benchmarks/versus-external-pools/dynamic-piscina.js rename to benchmarks/versus-external-pools/dynamic-piscina.mjs index 6b835d0e..6fcc6793 100644 --- a/benchmarks/versus-external-pools/dynamic-piscina.js +++ b/benchmarks/versus-external-pools/dynamic-piscina.mjs @@ -1,5 +1,5 @@ // IMPORT LIBRARIES -const Piscina = require('piscina') +import Piscina from 'piscina' // FINISH IMPORT LIBRARIES const size = parseInt(process.env.POOL_SIZE) const iterations = parseInt(process.env.NUM_ITERATIONS) @@ -10,7 +10,7 @@ const data = { } const piscina = new Piscina({ - filename: './workers/piscina/function-to-bench-worker.js', + filename: './workers/piscina/function-to-bench-worker.mjs', minThreads: size, maxThreads: size * 3, idleTimeout: 60000 // this is the same as poolifier default @@ -26,4 +26,4 @@ async function run () { process.exit() } -run() +await run() diff --git a/benchmarks/versus-external-pools/dynamic-poolifier.js b/benchmarks/versus-external-pools/dynamic-poolifier.mjs similarity index 83% rename from benchmarks/versus-external-pools/dynamic-poolifier.js rename to benchmarks/versus-external-pools/dynamic-poolifier.mjs index 20628421..34adba05 100644 --- a/benchmarks/versus-external-pools/dynamic-poolifier.js +++ b/benchmarks/versus-external-pools/dynamic-poolifier.mjs @@ -1,5 +1,5 @@ // IMPORT LIBRARIES -const { DynamicThreadPool } = require('poolifier') +import { DynamicThreadPool } from 'poolifier' // FINISH IMPORT LIBRARIES const size = parseInt(process.env.POOL_SIZE) const iterations = parseInt(process.env.NUM_ITERATIONS) @@ -12,7 +12,7 @@ const data = { const dynamicPool = new DynamicThreadPool( size, size * 3, - './workers/poolifier/function-to-bench-worker.js' + './workers/poolifier/function-to-bench-worker.mjs' ) async function run () { @@ -25,4 +25,4 @@ async function run () { process.exit() } -run() +await run() diff --git a/benchmarks/versus-external-pools/dynamic-tinypool.mjs b/benchmarks/versus-external-pools/dynamic-tinypool.mjs index 68d73b67..a28de9b5 100644 --- a/benchmarks/versus-external-pools/dynamic-tinypool.mjs +++ b/benchmarks/versus-external-pools/dynamic-tinypool.mjs @@ -10,7 +10,7 @@ const data = { } const tinypool = new Tinypool({ - filename: './workers/tinypool/function-to-bench-worker.js', + filename: './workers/tinypool/function-to-bench-worker.mjs', minThreads: size, maxThreads: size * 3, idleTimeout: 60000 // this is the same as poolifier default @@ -26,4 +26,4 @@ async function run () { process.exit() } -run() +await run() diff --git a/benchmarks/versus-external-pools/dynamic-worker-nodes.js b/benchmarks/versus-external-pools/dynamic-worker-nodes.mjs similarity index 82% rename from benchmarks/versus-external-pools/dynamic-worker-nodes.js rename to benchmarks/versus-external-pools/dynamic-worker-nodes.mjs index 47484528..a2622f9c 100644 --- a/benchmarks/versus-external-pools/dynamic-worker-nodes.js +++ b/benchmarks/versus-external-pools/dynamic-worker-nodes.mjs @@ -1,5 +1,6 @@ // IMPORT LIBRARIES -const WorkerNodes = require('worker-nodes') +import { resolve } from 'path' +import WorkerNodes from 'worker-nodes' // FINISH IMPORT LIBRARIES const size = parseInt(process.env.POOL_SIZE) const iterations = parseInt(process.env.NUM_ITERATIONS) @@ -10,7 +11,7 @@ const data = { } const workerNodes = new WorkerNodes( - require.resolve('./workers/worker-nodes/function-to-bench-worker'), + resolve('./workers/worker-nodes/function-to-bench-worker'), { minWorkers: size, maxWorkers: size * 3, @@ -28,4 +29,4 @@ async function run () { process.exit() } -run() +await run() diff --git a/benchmarks/versus-external-pools/dynamic-workerpool.js b/benchmarks/versus-external-pools/dynamic-workerpool.mjs similarity index 85% rename from benchmarks/versus-external-pools/dynamic-workerpool.js rename to benchmarks/versus-external-pools/dynamic-workerpool.mjs index 04d90ab2..072aa6fd 100644 --- a/benchmarks/versus-external-pools/dynamic-workerpool.js +++ b/benchmarks/versus-external-pools/dynamic-workerpool.mjs @@ -1,5 +1,5 @@ // IMPORT LIBRARIES -const workerpool = require('workerpool') +import workerpool from 'workerpool' // FINISH IMPORT LIBRARIES const size = parseInt(process.env.POOL_SIZE) const iterations = parseInt(process.env.NUM_ITERATIONS) @@ -10,7 +10,7 @@ const dataArray = [ ] const workerPool = workerpool.pool( - './workers/workerpool/function-to-bench-worker.js', + './workers/workerpool/function-to-bench-worker.mjs', { minWorkers: size, maxWorkers: size * 3, @@ -28,4 +28,4 @@ async function run () { process.exit() } -run() +await run() diff --git a/benchmarks/versus-external-pools/fixed-microjob.js b/benchmarks/versus-external-pools/fixed-microjob.mjs similarity index 85% rename from benchmarks/versus-external-pools/fixed-microjob.js rename to benchmarks/versus-external-pools/fixed-microjob.mjs index b61dcd94..f4e121a5 100644 --- a/benchmarks/versus-external-pools/fixed-microjob.js +++ b/benchmarks/versus-external-pools/fixed-microjob.mjs @@ -1,8 +1,8 @@ // IMPORT LIBRARIES -const { job, start } = require('microjob') +import { job, start } from 'microjob' // FINISH IMPORT LIBRARIES // IMPORT FUNCTION TO BENCH -const functionToBench = require('./functions/function-to-bench') +import functionToBench from './functions/function-to-bench.mjs' // FINISH IMPORT FUNCTION TO BENCH const size = parseInt(process.env.POOL_SIZE) const iterations = parseInt(process.env.NUM_ITERATIONS) @@ -30,4 +30,4 @@ async function run () { process.exit() } -run() +await run() diff --git a/benchmarks/versus-external-pools/fixed-piscina.js b/benchmarks/versus-external-pools/fixed-piscina.mjs similarity index 85% rename from benchmarks/versus-external-pools/fixed-piscina.js rename to benchmarks/versus-external-pools/fixed-piscina.mjs index 5ddc612f..f13b996a 100644 --- a/benchmarks/versus-external-pools/fixed-piscina.js +++ b/benchmarks/versus-external-pools/fixed-piscina.mjs @@ -1,5 +1,5 @@ // IMPORT LIBRARIES -const Piscina = require('piscina') +import Piscina from 'piscina' // FINISH IMPORT LIBRARIES const size = parseInt(process.env.POOL_SIZE) const iterations = parseInt(process.env.NUM_ITERATIONS) @@ -10,7 +10,7 @@ const data = { } const piscina = new Piscina({ - filename: './workers/piscina/function-to-bench-worker.js', + filename: './workers/piscina/function-to-bench-worker.mjs', minThreads: size, maxThreads: size, idleTimeout: 60000 // this is the same as poolifier default @@ -26,4 +26,4 @@ async function run () { process.exit() } -run() +await run() diff --git a/benchmarks/versus-external-pools/fixed-poolifier.js b/benchmarks/versus-external-pools/fixed-poolifier.mjs similarity index 83% rename from benchmarks/versus-external-pools/fixed-poolifier.js rename to benchmarks/versus-external-pools/fixed-poolifier.mjs index 2a5e599a..aa922be8 100644 --- a/benchmarks/versus-external-pools/fixed-poolifier.js +++ b/benchmarks/versus-external-pools/fixed-poolifier.mjs @@ -1,5 +1,5 @@ // IMPORT LIBRARIES -const { FixedThreadPool } = require('poolifier') +import { FixedThreadPool } from 'poolifier' // FINISH IMPORT LIBRARIES const size = parseInt(process.env.POOL_SIZE) const iterations = parseInt(process.env.NUM_ITERATIONS) @@ -11,7 +11,7 @@ const data = { const fixedPool = new FixedThreadPool( size, - './workers/poolifier/function-to-bench-worker.js' + './workers/poolifier/function-to-bench-worker.mjs' ) async function run () { @@ -24,4 +24,4 @@ async function run () { process.exit() } -run() +await run() diff --git a/benchmarks/versus-external-pools/fixed-threadwork.js b/benchmarks/versus-external-pools/fixed-threadwork.mjs similarity index 89% rename from benchmarks/versus-external-pools/fixed-threadwork.js rename to benchmarks/versus-external-pools/fixed-threadwork.mjs index d21fae6a..190abc1d 100644 --- a/benchmarks/versus-external-pools/fixed-threadwork.js +++ b/benchmarks/versus-external-pools/fixed-threadwork.mjs @@ -1,5 +1,5 @@ // IMPORT LIBRARIES -const threadPool = require('./pool-threadwork') +import threadPool from './pool-threadwork' // FINISH IMPORT LIBRARIES const iterations = parseInt(process.env.NUM_ITERATIONS) const data = { @@ -18,4 +18,4 @@ async function run () { process.exit() } -run() +await run() diff --git a/benchmarks/versus-external-pools/fixed-tinypool.mjs b/benchmarks/versus-external-pools/fixed-tinypool.mjs index 0875e3f4..9889a756 100644 --- a/benchmarks/versus-external-pools/fixed-tinypool.mjs +++ b/benchmarks/versus-external-pools/fixed-tinypool.mjs @@ -10,7 +10,7 @@ const data = { } const tinypool = new Tinypool({ - filename: './workers/tinypool/function-to-bench-worker.js', + filename: './workers/tinypool/function-to-bench-worker.mjs', minThreads: size, maxThreads: size, idleTimeout: 60000 // this is the same as poolifier default @@ -26,4 +26,4 @@ async function run () { process.exit() } -run() +await run() diff --git a/benchmarks/versus-external-pools/fixed-worker-nodes.js b/benchmarks/versus-external-pools/fixed-worker-nodes.mjs similarity index 82% rename from benchmarks/versus-external-pools/fixed-worker-nodes.js rename to benchmarks/versus-external-pools/fixed-worker-nodes.mjs index 49f8637d..67885117 100644 --- a/benchmarks/versus-external-pools/fixed-worker-nodes.js +++ b/benchmarks/versus-external-pools/fixed-worker-nodes.mjs @@ -1,5 +1,6 @@ // IMPORT LIBRARIES -const WorkerNodes = require('worker-nodes') +import { resolve } from 'path' +import WorkerNodes from 'worker-nodes' // FINISH IMPORT LIBRARIES const size = parseInt(process.env.POOL_SIZE) const iterations = parseInt(process.env.NUM_ITERATIONS) @@ -10,7 +11,7 @@ const data = { } const workerNodes = new WorkerNodes( - require.resolve('./workers/worker-nodes/function-to-bench-worker'), + resolve('./workers/worker-nodes/function-to-bench-worker'), { minWorkers: size, maxWorkers: size, @@ -28,4 +29,4 @@ async function run () { process.exit() } -run() +await run() diff --git a/benchmarks/versus-external-pools/fixed-workerpool.js b/benchmarks/versus-external-pools/fixed-workerpool.mjs similarity index 85% rename from benchmarks/versus-external-pools/fixed-workerpool.js rename to benchmarks/versus-external-pools/fixed-workerpool.mjs index cabdd9e7..c5529194 100644 --- a/benchmarks/versus-external-pools/fixed-workerpool.js +++ b/benchmarks/versus-external-pools/fixed-workerpool.mjs @@ -1,5 +1,5 @@ // IMPORT LIBRARIES -const workerpool = require('workerpool') +import workerpool from 'workerpool' // FINISH IMPORT LIBRARIES const size = parseInt(process.env.POOL_SIZE) const iterations = parseInt(process.env.NUM_ITERATIONS) @@ -10,7 +10,7 @@ const dataArray = [ ] const workerPool = workerpool.pool( - './workers/workerpool/function-to-bench-worker.js', + './workers/workerpool/function-to-bench-worker.mjs', { minWorkers: size, maxWorkers: size, @@ -28,4 +28,4 @@ async function run () { process.exit() } -run() +await run() diff --git a/benchmarks/versus-external-pools/functions/function-to-bench.js b/benchmarks/versus-external-pools/functions/function-to-bench.mjs similarity index 91% rename from benchmarks/versus-external-pools/functions/function-to-bench.js rename to benchmarks/versus-external-pools/functions/function-to-bench.mjs index b95f560f..4705273c 100644 --- a/benchmarks/versus-external-pools/functions/function-to-bench.js +++ b/benchmarks/versus-external-pools/functions/function-to-bench.mjs @@ -1,12 +1,13 @@ +import crypto from 'crypto' +import fs from 'fs' + /** * The worker function to execute during pools benchmarks. * NOTE: This function requires to be self-contained, thread-safe and re-entrant. * @param {*} data The worker data. * @returns {*} The result. */ -function functionToBench (data) { - const crypto = require('crypto') - const fs = require('fs') +export default function functionToBench (data) { const TaskTypes = { CPU_INTENSIVE: 'CPU_INTENSIVE', IO_INTENSIVE: 'IO_INTENSIVE' @@ -47,5 +48,3 @@ function functionToBench (data) { throw new Error(`Unknown task type: ${data.taskType}`) } } - -module.exports = functionToBench diff --git a/benchmarks/versus-external-pools/hyperfine_benchmarks.sh b/benchmarks/versus-external-pools/hyperfine_benchmarks.sh index 1be3c4a9..f78ea468 100755 --- a/benchmarks/versus-external-pools/hyperfine_benchmarks.sh +++ b/benchmarks/versus-external-pools/hyperfine_benchmarks.sh @@ -1,18 +1,18 @@ #!/usr/bin/env bash -hyperfine --export-markdown BENCH-100000.md --min-runs 20 --prepare 'sleep 2' --warmup 2 \ - 'node dynamic-poolifier.js' \ - 'node fixed-poolifier.js' \ - 'node dynamic-piscina.js' \ - 'node fixed-piscina.js' \ +hyperfine --export-markdown BENCH-100000.md --min-runs 20 --prepare 'sleep 2' --warmup 2 --show-output \ + 'node dynamic-poolifier.mjs' \ + 'node fixed-poolifier.mjs' \ + 'node dynamic-piscina.mjs' \ + 'node fixed-piscina.mjs' \ 'node fixed-tinypool.mjs' \ 'node dynamic-tinypool.mjs' \ - 'node dynamic-workerpool.js' \ - 'node fixed-workerpool.js' \ - 'node dynamic-node-worker-threads-pool.js' \ - 'node static-node-worker-threads-pool.js' \ - 'node threadjs.js' \ - 'node fixed-threadwork.js' \ - 'node fixed-microjob.js' \ - 'node dynamic-worker-nodes.js' \ - 'node fixed-worker-nodes.js' + 'node dynamic-workerpool.mjs' \ + 'node fixed-workerpool.mjs' \ + 'node dynamic-node-worker-threads-pool.mjs' \ + 'node static-node-worker-threads-pool.mjs' \ + 'node threadjs.mjs' \ + 'node fixed-threadwork.mjs' \ + 'node fixed-microjob.mjs' \ + 'node dynamic-worker-nodes.mjs' \ + 'node fixed-worker-nodes.mjs' diff --git a/benchmarks/versus-external-pools/pool-threadwork.js b/benchmarks/versus-external-pools/pool-threadwork.js deleted file mode 100644 index 2a2844f0..00000000 --- a/benchmarks/versus-external-pools/pool-threadwork.js +++ /dev/null @@ -1,9 +0,0 @@ -// IMPORT LIBRARIES -const { ThreadPool } = require('threadwork') -// FINISH IMPORT LIBRARIES -// IMPORT FUNCTION TO BENCH -const functionToBench = require('./functions/function-to-bench') -// FINISH IMPORT FUNCTION TO BENCH -const size = parseInt(process.env.POOL_SIZE) - -module.exports = new ThreadPool({ task: functionToBench, size }) diff --git a/benchmarks/versus-external-pools/pool-threadwork.mjs b/benchmarks/versus-external-pools/pool-threadwork.mjs new file mode 100644 index 00000000..4541e58c --- /dev/null +++ b/benchmarks/versus-external-pools/pool-threadwork.mjs @@ -0,0 +1,9 @@ +// IMPORT LIBRARIES +import { ThreadPool } from 'threadwork' +// FINISH IMPORT LIBRARIES +// IMPORT FUNCTION TO BENCH +import functionToBench from './functions/function-to-bench.mjs' +// FINISH IMPORT FUNCTION TO BENCH +const size = parseInt(process.env.POOL_SIZE) + +export default new ThreadPool({ task: functionToBench, size }) diff --git a/benchmarks/versus-external-pools/static-node-worker-threads-pool.js b/benchmarks/versus-external-pools/static-node-worker-threads-pool.mjs similarity index 82% rename from benchmarks/versus-external-pools/static-node-worker-threads-pool.js rename to benchmarks/versus-external-pools/static-node-worker-threads-pool.mjs index 75f3d2a4..b943be5d 100644 --- a/benchmarks/versus-external-pools/static-node-worker-threads-pool.js +++ b/benchmarks/versus-external-pools/static-node-worker-threads-pool.mjs @@ -1,8 +1,8 @@ // IMPORT LIBRARIES -const { StaticPool } = require('node-worker-threads-pool') +import { StaticPool } from 'node-worker-threads-pool' // FINISH IMPORT LIBRARIES // IMPORT FUNCTION TO BENCH -const functionToBench = require('./functions/function-to-bench') +import functionToBench from './functions/function-to-bench.mjs' // FINISH IMPORT FUNCTION TO BENCH const size = parseInt(process.env.POOL_SIZE) const iterations = parseInt(process.env.NUM_ITERATIONS) @@ -27,4 +27,4 @@ async function run () { process.exit() } -run() +await run() diff --git a/benchmarks/versus-external-pools/threadjs.js b/benchmarks/versus-external-pools/threadjs.mjs similarity index 86% rename from benchmarks/versus-external-pools/threadjs.js rename to benchmarks/versus-external-pools/threadjs.mjs index ee9178e9..f6c06eec 100644 --- a/benchmarks/versus-external-pools/threadjs.js +++ b/benchmarks/versus-external-pools/threadjs.mjs @@ -1,5 +1,5 @@ // IMPORT LIBRARIES -const { spawn, Worker } = require('threads') +import { Worker, spawn } from 'threads' // FINISH IMPORT LIBRARIES const size = parseInt(process.env.POOL_SIZE) const iterations = parseInt(process.env.NUM_ITERATIONS) @@ -14,7 +14,7 @@ const workers = [] async function poolify () { for (let i = 0; i < size; i++) { const worker = await spawn( - new Worker('./workers/threadjs/function-to-bench-worker.js') + new Worker('./workers/threadjs/function-to-bench-worker.mjs') ) workers.push(worker) } @@ -32,4 +32,4 @@ async function run () { process.exit() } -run() +await run() diff --git a/benchmarks/versus-external-pools/workers/piscina/function-to-bench-worker.js b/benchmarks/versus-external-pools/workers/piscina/function-to-bench-worker.js deleted file mode 100644 index 9fa8b472..00000000 --- a/benchmarks/versus-external-pools/workers/piscina/function-to-bench-worker.js +++ /dev/null @@ -1,3 +0,0 @@ -'use strict' -const functionToBench = require('../../functions/function-to-bench') -module.exports = functionToBench diff --git a/benchmarks/versus-external-pools/workers/piscina/function-to-bench-worker.mjs b/benchmarks/versus-external-pools/workers/piscina/function-to-bench-worker.mjs new file mode 100644 index 00000000..3a335928 --- /dev/null +++ b/benchmarks/versus-external-pools/workers/piscina/function-to-bench-worker.mjs @@ -0,0 +1,2 @@ +import functionToBench from '../../functions/function-to-bench.mjs' +export default functionToBench diff --git a/benchmarks/versus-external-pools/workers/poolifier/function-to-bench-worker.js b/benchmarks/versus-external-pools/workers/poolifier/function-to-bench-worker.js deleted file mode 100644 index 99af6ea6..00000000 --- a/benchmarks/versus-external-pools/workers/poolifier/function-to-bench-worker.js +++ /dev/null @@ -1,4 +0,0 @@ -'use strict' -const { ThreadWorker } = require('poolifier') -const functionToBench = require('../../functions/function-to-bench') -module.exports = new ThreadWorker(functionToBench) diff --git a/benchmarks/versus-external-pools/workers/poolifier/function-to-bench-worker.mjs b/benchmarks/versus-external-pools/workers/poolifier/function-to-bench-worker.mjs new file mode 100644 index 00000000..f889e44a --- /dev/null +++ b/benchmarks/versus-external-pools/workers/poolifier/function-to-bench-worker.mjs @@ -0,0 +1,3 @@ +import { ThreadWorker } from 'poolifier' +import functionToBench from '../../functions/function-to-bench.mjs' +export default new ThreadWorker(functionToBench) diff --git a/benchmarks/versus-external-pools/workers/threadjs/function-to-bench-worker.js b/benchmarks/versus-external-pools/workers/threadjs/function-to-bench-worker.js deleted file mode 100644 index 71e48388..00000000 --- a/benchmarks/versus-external-pools/workers/threadjs/function-to-bench-worker.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict' -const { expose } = require('threads/worker') -const functionToBench = require('../../functions/function-to-bench') - -expose({ - exposedFunction (data) { - return functionToBench(data) - } -}) diff --git a/benchmarks/versus-external-pools/workers/threadjs/function-to-bench-worker.mjs b/benchmarks/versus-external-pools/workers/threadjs/function-to-bench-worker.mjs new file mode 100644 index 00000000..d77174f9 --- /dev/null +++ b/benchmarks/versus-external-pools/workers/threadjs/function-to-bench-worker.mjs @@ -0,0 +1,8 @@ +import { expose } from 'threads/worker' +import functionToBench from '../../functions/function-to-bench.mjs' + +expose({ + exposedFunction (data) { + return functionToBench(data) + } +}) diff --git a/benchmarks/versus-external-pools/workers/tinypool/function-to-bench-worker.js b/benchmarks/versus-external-pools/workers/tinypool/function-to-bench-worker.js deleted file mode 100644 index 9fa8b472..00000000 --- a/benchmarks/versus-external-pools/workers/tinypool/function-to-bench-worker.js +++ /dev/null @@ -1,3 +0,0 @@ -'use strict' -const functionToBench = require('../../functions/function-to-bench') -module.exports = functionToBench diff --git a/benchmarks/versus-external-pools/workers/tinypool/function-to-bench-worker.mjs b/benchmarks/versus-external-pools/workers/tinypool/function-to-bench-worker.mjs new file mode 100644 index 00000000..3a335928 --- /dev/null +++ b/benchmarks/versus-external-pools/workers/tinypool/function-to-bench-worker.mjs @@ -0,0 +1,2 @@ +import functionToBench from '../../functions/function-to-bench.mjs' +export default functionToBench diff --git a/benchmarks/versus-external-pools/workers/worker-nodes/function-to-bench-worker.js b/benchmarks/versus-external-pools/workers/worker-nodes/function-to-bench-worker.js deleted file mode 100644 index b9a9ea26..00000000 --- a/benchmarks/versus-external-pools/workers/worker-nodes/function-to-bench-worker.js +++ /dev/null @@ -1,3 +0,0 @@ -'use strict' -const functionToBench = require('../../functions/function-to-bench') -module.exports = { functionToBench } diff --git a/benchmarks/versus-external-pools/workers/worker-nodes/function-to-bench-worker.mjs b/benchmarks/versus-external-pools/workers/worker-nodes/function-to-bench-worker.mjs new file mode 100644 index 00000000..afa4ce13 --- /dev/null +++ b/benchmarks/versus-external-pools/workers/worker-nodes/function-to-bench-worker.mjs @@ -0,0 +1,2 @@ +import functionToBench from '../../functions/function-to-bench.mjs' +export { functionToBench } diff --git a/benchmarks/versus-external-pools/workers/workerpool/function-to-bench-worker.js b/benchmarks/versus-external-pools/workers/workerpool/function-to-bench-worker.mjs similarity index 65% rename from benchmarks/versus-external-pools/workers/workerpool/function-to-bench-worker.js rename to benchmarks/versus-external-pools/workers/workerpool/function-to-bench-worker.mjs index a883ce43..a1b8d261 100644 --- a/benchmarks/versus-external-pools/workers/workerpool/function-to-bench-worker.js +++ b/benchmarks/versus-external-pools/workers/workerpool/function-to-bench-worker.mjs @@ -1,6 +1,5 @@ -'use strict' -const workerpool = require('workerpool') -const functionToBench = require('../../functions/function-to-bench') +import workerpool from 'workerpool' +import functionToBench from '../../functions/function-to-bench.mjs' function workerPoolWrapperFunctionToBench (testName, taskType, taskSize) { return functionToBench({ -- 2.34.1