From 8f810074232deefe64634a8942b1db5b8d3bb0dc Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 25 Jun 2023 16:13:27 +0200 Subject: [PATCH] refactor: convert to ESM benchmarks code MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- ...{benchmarks-types.js => benchmarks-types.mjs} | 2 +- ...{benchmarks-utils.js => benchmarks-utils.mjs} | 16 ++++++---------- benchmarks/internal/bench.mjs | 8 ++++++-- benchmarks/internal/cluster-worker.mjs | 4 ++-- benchmarks/internal/thread-worker.mjs | 4 ++-- .../worker-selection/{less.js => less.mjs} | 4 ++-- .../{round-robin.js => round-robin.mjs} | 2 +- 7 files changed, 20 insertions(+), 20 deletions(-) rename benchmarks/{benchmarks-types.js => benchmarks-types.mjs} (83%) rename benchmarks/{benchmarks-utils.js => benchmarks-utils.mjs} (95%) rename benchmarks/worker-selection/{less.js => less.mjs} (97%) rename benchmarks/worker-selection/{round-robin.js => round-robin.mjs} (97%) diff --git a/benchmarks/benchmarks-types.js b/benchmarks/benchmarks-types.mjs similarity index 83% rename from benchmarks/benchmarks-types.js rename to benchmarks/benchmarks-types.mjs index 4411fbbe..f7d8bdb9 100644 --- a/benchmarks/benchmarks-types.js +++ b/benchmarks/benchmarks-types.mjs @@ -15,4 +15,4 @@ const WorkerTypes = { cluster: 'cluster' } -module.exports = { PoolTypes, WorkerFunctions, WorkerTypes } +export { PoolTypes, WorkerFunctions, WorkerTypes } diff --git a/benchmarks/benchmarks-utils.js b/benchmarks/benchmarks-utils.mjs similarity index 95% rename from benchmarks/benchmarks-utils.js rename to benchmarks/benchmarks-utils.mjs index 6195a983..45e8cc0e 100644 --- a/benchmarks/benchmarks-utils.js +++ b/benchmarks/benchmarks-utils.mjs @@ -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, diff --git a/benchmarks/internal/bench.mjs b/benchmarks/internal/bench.mjs index 6fad24c7..fe34a220 100644 --- a/benchmarks/internal/bench.mjs +++ b/benchmarks/internal/bench.mjs @@ -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 diff --git a/benchmarks/internal/cluster-worker.mjs b/benchmarks/internal/cluster-worker.mjs index 511ad2eb..50e4a324 100644 --- a/benchmarks/internal/cluster-worker.mjs +++ b/benchmarks/internal/cluster-worker.mjs @@ -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 diff --git a/benchmarks/internal/thread-worker.mjs b/benchmarks/internal/thread-worker.mjs index 4f66a89a..4e3c1050 100644 --- a/benchmarks/internal/thread-worker.mjs +++ b/benchmarks/internal/thread-worker.mjs @@ -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 diff --git a/benchmarks/worker-selection/less.js b/benchmarks/worker-selection/less.mjs similarity index 97% rename from benchmarks/worker-selection/less.js rename to benchmarks/worker-selection/less.mjs index 3733cf6d..e839107d 100644 --- a/benchmarks/worker-selection/less.js +++ b/benchmarks/worker-selection/less.mjs @@ -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, diff --git a/benchmarks/worker-selection/round-robin.js b/benchmarks/worker-selection/round-robin.mjs similarity index 97% rename from benchmarks/worker-selection/round-robin.js rename to benchmarks/worker-selection/round-robin.mjs index 67d3a365..b724a04a 100644 --- a/benchmarks/worker-selection/round-robin.js +++ b/benchmarks/worker-selection/round-robin.mjs @@ -1,4 +1,4 @@ -const Benchmark = require('benny') +import Benchmark from 'benny' function generateWorkersArray (numberOfWorkers) { return [...Array(numberOfWorkers).keys()] -- 2.34.1