refactor: convert to ESM benchmarks code
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 25 Jun 2023 14:13:27 +0000 (16:13 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 25 Jun 2023 14:13:27 +0000 (16:13 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
benchmarks/benchmarks-types.mjs [moved from benchmarks/benchmarks-types.js with 83% similarity]
benchmarks/benchmarks-utils.mjs [moved from benchmarks/benchmarks-utils.js with 95% similarity]
benchmarks/internal/bench.mjs
benchmarks/internal/cluster-worker.mjs
benchmarks/internal/thread-worker.mjs
benchmarks/worker-selection/less.mjs [moved from benchmarks/worker-selection/less.js with 97% similarity]
benchmarks/worker-selection/round-robin.mjs [moved from benchmarks/worker-selection/round-robin.js with 97% similarity]

similarity index 83%
rename from benchmarks/benchmarks-types.js
rename to benchmarks/benchmarks-types.mjs
index 4411fbbe3a4a39499e81bf45f5892905fafd7981..f7d8bdb9d9002b5d34169af5a61eb9fb192aab9e 100644 (file)
@@ -15,4 +15,4 @@ const WorkerTypes = {
   cluster: 'cluster'
 }
 
-module.exports = { PoolTypes, WorkerFunctions, WorkerTypes }
+export { PoolTypes, WorkerFunctions, WorkerTypes }
similarity index 95%
rename from benchmarks/benchmarks-utils.js
rename to benchmarks/benchmarks-utils.mjs
index 6195a983c3fe98da9e8f68e06dbc96818773c1fc..45e8cc0ea5882ae0804664d8f25e88f7265f6fe8 100644 (file)
@@ -1,16 +1,12 @@
-const crypto = require('crypto')
-const fs = require('fs')
-const {
+import crypto from 'crypto'
+import fs from 'fs'
+import {
   DynamicClusterPool,
   DynamicThreadPool,
   FixedClusterPool,
   FixedThreadPool
-} = require('../lib')
-const {
-  PoolTypes,
-  WorkerFunctions,
-  WorkerTypes
-} = require('./benchmarks-types')
+} from '../lib/index.mjs'
+import { PoolTypes, WorkerFunctions, WorkerTypes } from './benchmarks-types.mjs'
 
 async function runTest (pool, { taskExecutions, workerData }) {
   return new Promise((resolve, reject) => {
@@ -151,7 +147,7 @@ function buildPool (workerType, poolType, poolSize, poolOptions) {
   }
 }
 
-module.exports = {
+export {
   WorkerFunctions,
   buildPool,
   executeWorkerFunction,
index 6fad24c76a85f1878a95c843eadcefc1fbcc8977..fe34a220bd2e5165909502ab146e24e4eb007348 100644 (file)
@@ -1,7 +1,11 @@
 import Benchmark from 'benny'
 import { WorkerChoiceStrategies } from '../../lib/index.mjs'
-import { PoolTypes, WorkerFunctions, WorkerTypes } from '../benchmarks-types.js'
-import { buildPool, runTest } from '../benchmarks-utils.js'
+import {
+  PoolTypes,
+  WorkerFunctions,
+  WorkerTypes
+} from '../benchmarks-types.mjs'
+import { buildPool, runTest } from '../benchmarks-utils.mjs'
 
 const poolSize = 30
 const taskExecutions = 1
index 511ad2eb7011956875951e02e7000be94afbcf29..50e4a324a98a580206db83a3dc3dc40bf80efc32 100644 (file)
@@ -1,7 +1,7 @@
 import { isMaster } from 'cluster'
 import { ClusterWorker } from '../../lib/index.mjs'
-import { executeWorkerFunction } from '../benchmarks-utils.js'
-import { WorkerFunctions } from '../benchmarks-types.js'
+import { executeWorkerFunction } from '../benchmarks-utils.mjs'
+import { WorkerFunctions } from '../benchmarks-types.mjs'
 
 const debug = false
 
index 4f66a89a7356c49813c27ff2150839be5ad0356d..4e3c10500e0edc8fde098d49fc633d585336fc0a 100644 (file)
@@ -1,7 +1,7 @@
 import { isMainThread } from 'worker_threads'
 import { ThreadWorker } from '../../lib/index.mjs'
-import { executeWorkerFunction } from '../benchmarks-utils.js'
-import { WorkerFunctions } from '../benchmarks-types.js'
+import { executeWorkerFunction } from '../benchmarks-utils.mjs'
+import { WorkerFunctions } from '../benchmarks-types.mjs'
 
 const debug = false
 
similarity index 97%
rename from benchmarks/worker-selection/less.js
rename to benchmarks/worker-selection/less.mjs
index 3733cf6d336b5835979db48093823b126daf2559..e839107d0978cacb32f6d55521bcc4455e5615f0 100644 (file)
@@ -1,5 +1,5 @@
-const Benchmark = require('benny')
-const { generateRandomInteger } = require('../benchmarks-utils')
+import Benchmark from 'benny'
+import { generateRandomInteger } from '../benchmarks-utils.mjs'
 
 function generateRandomTasksMap (
   numberOfWorkers,
similarity index 97%
rename from benchmarks/worker-selection/round-robin.js
rename to benchmarks/worker-selection/round-robin.mjs
index 67d3a365e7e9f96394e46a970d97cced6689a2a0..b724a04ad5f6acc009bb86b0fd7e32318757a07b 100644 (file)
@@ -1,4 +1,4 @@
-const Benchmark = require('benny')
+import Benchmark from 'benny'
 
 function generateWorkersArray (numberOfWorkers) {
   return [...Array(numberOfWorkers).keys()]