From: Jérôme Benoit Date: Sun, 25 Jun 2023 14:13:27 +0000 (+0200) Subject: refactor: convert to ESM benchmarks code X-Git-Tag: v2.6.4~32 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=8f810074232deefe64634a8942b1db5b8d3bb0dc;hp=8a97042123ae9a0404637711b8da7c6e7e4424c7;p=poolifier.git refactor: convert to ESM benchmarks code Signed-off-by: Jérôme Benoit --- 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()]