refactor: convert benchmarks code to ESM
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 25 Jun 2023 13:03:57 +0000 (15:03 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 25 Jun 2023 13:03:57 +0000 (15:03 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
31 files changed:
benchmarks/versus-external-pools/BENCH-100000.md
benchmarks/versus-external-pools/dynamic-node-worker-threads-pool.mjs [moved from benchmarks/versus-external-pools/dynamic-node-worker-threads-pool.js with 83% similarity]
benchmarks/versus-external-pools/dynamic-piscina.mjs [moved from benchmarks/versus-external-pools/dynamic-piscina.js with 85% similarity]
benchmarks/versus-external-pools/dynamic-poolifier.mjs [moved from benchmarks/versus-external-pools/dynamic-poolifier.js with 83% similarity]
benchmarks/versus-external-pools/dynamic-tinypool.mjs
benchmarks/versus-external-pools/dynamic-worker-nodes.mjs [moved from benchmarks/versus-external-pools/dynamic-worker-nodes.js with 82% similarity]
benchmarks/versus-external-pools/dynamic-workerpool.mjs [moved from benchmarks/versus-external-pools/dynamic-workerpool.js with 85% similarity]
benchmarks/versus-external-pools/fixed-microjob.mjs [moved from benchmarks/versus-external-pools/fixed-microjob.js with 85% similarity]
benchmarks/versus-external-pools/fixed-piscina.mjs [moved from benchmarks/versus-external-pools/fixed-piscina.js with 85% similarity]
benchmarks/versus-external-pools/fixed-poolifier.mjs [moved from benchmarks/versus-external-pools/fixed-poolifier.js with 83% similarity]
benchmarks/versus-external-pools/fixed-threadwork.mjs [moved from benchmarks/versus-external-pools/fixed-threadwork.js with 89% similarity]
benchmarks/versus-external-pools/fixed-tinypool.mjs
benchmarks/versus-external-pools/fixed-worker-nodes.mjs [moved from benchmarks/versus-external-pools/fixed-worker-nodes.js with 82% similarity]
benchmarks/versus-external-pools/fixed-workerpool.mjs [moved from benchmarks/versus-external-pools/fixed-workerpool.js with 85% similarity]
benchmarks/versus-external-pools/functions/function-to-bench.mjs [moved from benchmarks/versus-external-pools/functions/function-to-bench.js with 91% similarity]
benchmarks/versus-external-pools/hyperfine_benchmarks.sh
benchmarks/versus-external-pools/pool-threadwork.js [deleted file]
benchmarks/versus-external-pools/pool-threadwork.mjs [new file with mode: 0644]
benchmarks/versus-external-pools/static-node-worker-threads-pool.mjs [moved from benchmarks/versus-external-pools/static-node-worker-threads-pool.js with 82% similarity]
benchmarks/versus-external-pools/threadjs.mjs [moved from benchmarks/versus-external-pools/threadjs.js with 86% similarity]
benchmarks/versus-external-pools/workers/piscina/function-to-bench-worker.js [deleted file]
benchmarks/versus-external-pools/workers/piscina/function-to-bench-worker.mjs [new file with mode: 0644]
benchmarks/versus-external-pools/workers/poolifier/function-to-bench-worker.js [deleted file]
benchmarks/versus-external-pools/workers/poolifier/function-to-bench-worker.mjs [new file with mode: 0644]
benchmarks/versus-external-pools/workers/threadjs/function-to-bench-worker.js [deleted file]
benchmarks/versus-external-pools/workers/threadjs/function-to-bench-worker.mjs [new file with mode: 0644]
benchmarks/versus-external-pools/workers/tinypool/function-to-bench-worker.js [deleted file]
benchmarks/versus-external-pools/workers/tinypool/function-to-bench-worker.mjs [new file with mode: 0644]
benchmarks/versus-external-pools/workers/worker-nodes/function-to-bench-worker.js [deleted file]
benchmarks/versus-external-pools/workers/worker-nodes/function-to-bench-worker.mjs [new file with mode: 0644]
benchmarks/versus-external-pools/workers/workerpool/function-to-bench-worker.mjs [moved from benchmarks/versus-external-pools/workers/workerpool/function-to-bench-worker.js with 65% similarity]

index 6144bdb4639f7979dfdf310de43f2744c0a8124a..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -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 |
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 0a56d1fd2326555ca7804d4850efb87670a517f2..743b01d64e2b6086af087311809825d56c533f6d 100644 (file)
@@ -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()
similarity index 85%
rename from benchmarks/versus-external-pools/dynamic-piscina.js
rename to benchmarks/versus-external-pools/dynamic-piscina.mjs
index 6b835d0ee37239460ca81c00564292da647cb224..6fcc6793869f38d236c9f956962ed871376fccb6 100644 (file)
@@ -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()
similarity index 83%
rename from benchmarks/versus-external-pools/dynamic-poolifier.js
rename to benchmarks/versus-external-pools/dynamic-poolifier.mjs
index 206284212eb5d40ff264fc004d7d5d32be408ca7..34adba055629ea518de1c0d3de7df2e36311447b 100644 (file)
@@ -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()
index 68d73b67381f4c5a987221693a98fd84a5a1a28b..a28de9b59f7e8e1e03f6de4146a768b4a91c3ff6 100644 (file)
@@ -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()
similarity index 82%
rename from benchmarks/versus-external-pools/dynamic-worker-nodes.js
rename to benchmarks/versus-external-pools/dynamic-worker-nodes.mjs
index 47484528791f03c61211bb1f813562892e7de2b2..a2622f9c0d5f685579c74ede404c6055233fbd9f 100644 (file)
@@ -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()
similarity index 85%
rename from benchmarks/versus-external-pools/dynamic-workerpool.js
rename to benchmarks/versus-external-pools/dynamic-workerpool.mjs
index 04d90ab209f4365968b6d7ecf2a6d130ed74779e..072aa6fd10fd3d77cf8ee0964bfeb494c16cee66 100644 (file)
@@ -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()
similarity index 85%
rename from benchmarks/versus-external-pools/fixed-microjob.js
rename to benchmarks/versus-external-pools/fixed-microjob.mjs
index b61dcd9438b70e029cb3890adb695761e5dbebeb..f4e121a549bdfdb1aca2f935eac690f503ad1171 100644 (file)
@@ -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()
similarity index 85%
rename from benchmarks/versus-external-pools/fixed-piscina.js
rename to benchmarks/versus-external-pools/fixed-piscina.mjs
index 5ddc612f642bea56b4663116c9f5ba860bfd84cb..f13b996a7aead8e3a2eeeecfee16cf06a59407de 100644 (file)
@@ -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()
similarity index 83%
rename from benchmarks/versus-external-pools/fixed-poolifier.js
rename to benchmarks/versus-external-pools/fixed-poolifier.mjs
index 2a5e599ab11aefc0948bb8ec208f3650ede4e02f..aa922be8a9928651519572177eeb728cb9fe72b3 100644 (file)
@@ -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()
similarity index 89%
rename from benchmarks/versus-external-pools/fixed-threadwork.js
rename to benchmarks/versus-external-pools/fixed-threadwork.mjs
index d21fae6a8e2179704af88fb420c40f2c338deb1a..190abc1d8c06f9524e50c4ea809a2a928a40fd1b 100644 (file)
@@ -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()
index 0875e3f4d513b1a737a908da80bf44d5d46548e9..9889a75667547dc4395ff274e6f574ad6d6b98d3 100644 (file)
@@ -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()
similarity index 82%
rename from benchmarks/versus-external-pools/fixed-worker-nodes.js
rename to benchmarks/versus-external-pools/fixed-worker-nodes.mjs
index 49f8637ded36feb2e43b2d3796607622b1ae7fc0..678851173f9bed7b6e127b8d4c7ba2e9bc7e6713 100644 (file)
@@ -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()
similarity index 85%
rename from benchmarks/versus-external-pools/fixed-workerpool.js
rename to benchmarks/versus-external-pools/fixed-workerpool.mjs
index cabdd9e794545c79e8a88ccc6e11eeb5ebd81ff7..c55291945515e0bb0391db472e5ea5e5e3c16547 100644 (file)
@@ -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()
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 b95f560f0807d7e9b3a638fe2106f609b5f368ca..4705273c07e1bd1437d84f75d2a74782747d8e11 100644 (file)
@@ -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
index 1be3c4a98bb1f630703325488f8fe256f899e49c..f78ea46867589820798bbec6e1aaa4c5d6b6d0b6 100755 (executable)
@@ -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 (file)
index 2a2844f..0000000
+++ /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 (file)
index 0000000..4541e58
--- /dev/null
@@ -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 })
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 75f3d2a438fd3cc1b1a963e626f6b2cccecff69d..b943be5d4a60e1531371ce5151af359cde815674 100644 (file)
@@ -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()
similarity index 86%
rename from benchmarks/versus-external-pools/threadjs.js
rename to benchmarks/versus-external-pools/threadjs.mjs
index ee9178e92b7954663efd9855f069476423d6bb06..f6c06eec48592425ee4e7346d0ad238b92afed65 100644 (file)
@@ -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 (file)
index 9fa8b47..0000000
+++ /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 (file)
index 0000000..3a33592
--- /dev/null
@@ -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 (file)
index 99af6ea..0000000
+++ /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 (file)
index 0000000..f889e44
--- /dev/null
@@ -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 (file)
index 71e4838..0000000
+++ /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 (file)
index 0000000..d77174f
--- /dev/null
@@ -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 (file)
index 9fa8b47..0000000
+++ /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 (file)
index 0000000..3a33592
--- /dev/null
@@ -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 (file)
index b9a9ea2..0000000
+++ /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 (file)
index 0000000..afa4ce1
--- /dev/null
@@ -0,0 +1,2 @@
+import functionToBench from '../../functions/function-to-bench.mjs'
+export { functionToBench }
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 a883ce438eb44be74200fd00791833be6935a9fd..a1b8d2618b6ce0e11b7f5e066623189e64909a35 100644 (file)
@@ -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({