-export const TaskFunctions = {
+const TaskFunctions = {
jsonIntegerSerialization: 'jsonIntegerSerialization',
fibonacci: 'fibonacci',
factorial: 'factorial',
readWriteFiles: 'readWriteFiles'
}
+
+module.exports = { TaskFunctions }
-import crypto from 'node:crypto'
-import assert from 'node:assert'
-import fs from 'node:fs'
-import Benchmark from 'benchmark'
-import {
+const crypto = require('node:crypto')
+const assert = require('node:assert')
+const fs = require('node:fs')
+const Benchmark = require('benchmark')
+const {
DynamicClusterPool,
DynamicThreadPool,
FixedClusterPool,
PoolTypes,
WorkerChoiceStrategies,
WorkerTypes
-} from '../lib/index.mjs'
-import { TaskFunctions } from './benchmarks-types.mjs'
+} = require('../lib/index.js')
+const { TaskFunctions } = require('./benchmarks-types.js')
-export const buildPoolifierPool = (
- workerType,
- poolType,
- poolSize,
- poolOptions
-) => {
+const buildPoolifierPool = (workerType, poolType, poolSize, poolOptions) => {
switch (poolType) {
case PoolTypes.fixed:
switch (workerType) {
case WorkerTypes.cluster:
return new FixedClusterPool(
poolSize,
- './benchmarks/internal/cluster-worker.mjs',
+ './benchmarks/internal/cluster-worker.js',
poolOptions
)
}
return new DynamicClusterPool(
Math.floor(poolSize / 2),
poolSize,
- './benchmarks/internal/cluster-worker.mjs',
+ './benchmarks/internal/cluster-worker.js',
poolOptions
)
}
}
}
-export const runPoolifierPool = async (
- pool,
- { taskExecutions, workerData }
-) => {
+const runPoolifierPool = async (pool, { taskExecutions, workerData }) => {
return await new Promise((resolve, reject) => {
let executions = 0
for (let i = 1; i <= taskExecutions; i++) {
})
}
-export const runPoolifierPoolBenchmark = async (
+const runPoolifierPoolBenchmark = async (
name,
pool,
{ taskExecutions, workerData }
})
}
-export const LIST_FORMATTER = new Intl.ListFormat('en-US', {
+const LIST_FORMATTER = new Intl.ListFormat('en-US', {
style: 'long',
type: 'conjunction'
})
-export const generateRandomInteger = (
- max = Number.MAX_SAFE_INTEGER,
- min = 0
-) => {
+const generateRandomInteger = (max = Number.MAX_SAFE_INTEGER, min = 0) => {
if (max < min || max < 0 || min < 0) {
throw new RangeError('Invalid interval')
}
return { ok: 1 }
}
-export const executeTaskFunction = data => {
+const executeTaskFunction = data => {
switch (data.function) {
case TaskFunctions.jsonIntegerSerialization:
return jsonIntegerSerialization(data.taskSize || 1000)
throw new Error('Unknown task function')
}
}
+
+module.exports = {
+ LIST_FORMATTER,
+ buildPoolifierPool,
+ executeTaskFunction,
+ generateRandomInteger,
+ runPoolifierPoolBenchmark
+}
WorkerTypes,
availableParallelism
} from '../../lib/index.mjs'
-import { TaskFunctions } from '../benchmarks-types.mjs'
+import { TaskFunctions } from '../benchmarks-types.js'
import {
buildPoolifierPool,
runPoolifierPoolBenchmark
-} from '../benchmarks-utils.mjs'
+} from '../benchmarks-utils.js'
const poolSize = availableParallelism()
const taskExecutions = 1
workerData
}
)
+
+// FixedClusterPool
+await runPoolifierPoolBenchmark(
+ 'Poolifier FixedClusterPool',
+ buildPoolifierPool(WorkerTypes.cluster, PoolTypes.fixed, poolSize),
+ {
+ taskExecutions,
+ workerData
+ }
+)
+
+// DynamicClusterPool
+await runPoolifierPoolBenchmark(
+ 'Poolifier DynamicClusterPool',
+ buildPoolifierPool(WorkerTypes.cluster, PoolTypes.dynamic, poolSize),
+ {
+ taskExecutions,
+ workerData
+ }
+)
-import { isPrimary } from 'node:cluster'
-import { ClusterWorker } from '../../lib/index.mjs'
-import { executeTaskFunction } from '../benchmarks-utils.mjs'
-import { TaskFunctions } from '../benchmarks-types.mjs'
+const { isPrimary } = require('node:cluster')
+const { ClusterWorker } = require('../../lib')
+const { executeTaskFunction } = require('../benchmarks-utils.js')
+const { TaskFunctions } = require('../benchmarks-types.js')
const taskFunction = data => {
data = data || {}
return res
}
-export default new ClusterWorker(taskFunction)
+module.exports = new ClusterWorker(taskFunction)
import { isMainThread } from 'node:worker_threads'
import { ThreadWorker } from '../../lib/index.mjs'
-import { executeTaskFunction } from '../benchmarks-utils.mjs'
-import { TaskFunctions } from '../benchmarks-types.mjs'
+import { executeTaskFunction } from '../benchmarks-utils.js'
+import { TaskFunctions } from '../benchmarks-types.js'
const taskFunction = data => {
data = data || {}
import Benchmark from 'benchmark'
-import { LIST_FORMATTER, generateRandomInteger } from '../benchmarks-utils.mjs'
+import { LIST_FORMATTER, generateRandomInteger } from '../benchmarks-utils.js'
function generateRandomTasksMap (
numberOfWorkers,
import Benchmark from 'benchmark'
-import { LIST_FORMATTER } from '../benchmarks-utils.mjs'
+import { LIST_FORMATTER } from '../benchmarks-utils.js'
function generateWorkersArray (numberOfWorkers) {
return [...Array(numberOfWorkers).keys()]
"@release-it/keep-a-changelog": "^4.0.0",
"@rollup/plugin-terser": "^0.4.3",
"@rollup/plugin-typescript": "^11.1.4",
- "@types/node": "^20.7.1",
+ "@types/node": "^20.7.2",
"@typescript-eslint/eslint-plugin": "^6.7.3",
"@typescript-eslint/parser": "^6.7.3",
"benchmark": "^2.1.4",
specifier: ^11.1.4
version: 11.1.4(rollup@3.29.4)(typescript@5.2.2)
'@types/node':
- specifier: ^20.7.1
- version: 20.7.1
+ specifier: ^20.7.2
+ version: 20.7.2
'@typescript-eslint/eslint-plugin':
specifier: ^6.7.3
version: 6.7.3(@typescript-eslint/parser@6.7.3)(eslint@8.50.0)(typescript@5.2.2)
lodash.merge: 4.6.2
lodash.uniq: 4.5.0
resolve-from: 5.0.0
- ts-node: 10.9.1(@types/node@20.7.1)(typescript@5.2.2)
+ ts-node: 10.9.1(@types/node@20.7.2)(typescript@5.2.2)
typescript: 5.2.2
transitivePeerDependencies:
- '@swc/core'
'@jest/schemas': 29.6.3
'@types/istanbul-lib-coverage': 2.0.4
'@types/istanbul-reports': 3.0.2
- '@types/node': 20.7.1
- '@types/yargs': 17.0.25
+ '@types/node': 20.7.2
+ '@types/yargs': 17.0.26
chalk: 4.1.2
dev: true
resolution: {integrity: sha512-ZUxbzKl0IfJILTS6t7ip5fQQM/J3TJYubDm3nMbgubNNYS62eXeUpoLUC8/7fJNiFYHTrGPQn7hspDUzIHX3UA==}
dependencies:
'@types/minimatch': 5.1.2
- '@types/node': 20.7.1
+ '@types/node': 20.7.2
dev: true
/@types/http-cache-semantics@4.0.2:
resolution: {integrity: sha512-4tT2UrL5LBqDwoed9wZ6N3umC4Yhz3W3FloMmiiG4JwmUJWpie0c7lcnUNd4gtMKuDEO4wRVS8B6Xa0uMRsMKg==}
dev: true
- /@types/node@20.7.1:
- resolution: {integrity: sha512-LT+OIXpp2kj4E2S/p91BMe+VgGX2+lfO+XTpfXhh+bCk2LkQtHZSub8ewFBMGP5ClysPjTDFa4sMI8Q3n4T0wg==}
+ /@types/node@20.7.2:
+ resolution: {integrity: sha512-RcdC3hOBOauLP+r/kRt27NrByYtDjsXyAuSbR87O6xpsvi763WI+5fbSIvYJrXnt9w4RuxhV6eAXfIs7aaf/FQ==}
dev: true
/@types/normalize-package-data@2.4.2:
resolution: {integrity: sha512-axdPBuLuEJt0c4yI5OZssC19K2Mq1uKdrfZBzuxLvaztgqUtFYZUNw7lETExPYJR9jdEoIg4mb7RQKRQzOkeGQ==}
dev: true
- /@types/yargs@17.0.25:
- resolution: {integrity: sha512-gy7iPgwnzNvxgAEi2bXOHWCVOG6f7xsprVJH4MjlAWeBmJ7vh/Y1kwMtUrs64ztf24zVIRCpr3n/z6gm9QIkgg==}
+ /@types/yargs@17.0.26:
+ resolution: {integrity: sha512-Y3vDy2X6zw/ZCumcwLpdhM5L7jmyGpmBCTYMHDLqT2IKVMYRRLdv6ZakA+wxhra6Z/3bwhNbNl9bDGXaFU+6rw==}
dependencies:
'@types/yargs-parser': 21.0.1
dev: true
dependencies:
'@types/node': 20.5.1
cosmiconfig: 8.3.6(typescript@5.2.2)
- ts-node: 10.9.1(@types/node@20.7.1)(typescript@5.2.2)
+ ts-node: 10.9.1(@types/node@20.7.2)(typescript@5.2.2)
typescript: 5.2.2
dev: true
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
dependencies:
'@jest/types': 29.6.3
- '@types/node': 20.7.1
+ '@types/node': 20.7.2
chalk: 4.1.2
ci-info: 3.8.0
graceful-fs: 4.2.11
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
dev: true
- /magic-string@0.30.3:
- resolution: {integrity: sha512-B7xGbll2fG/VjP+SWg4sX3JynwIU0mjoTc6MPpKNuIvftk6u6vqhDnk1R80b8C2GBR6ywqy+1DcKBrevBg+bmw==}
+ /magic-string@0.30.4:
+ resolution: {integrity: sha512-Q/TKtsC5BPm0kGqgBIF9oXAs/xEf2vRKiIB4wCRQTJOQIByZ1d+NnUOotvJOvNpi5RNIgVOMC3pOuaP1ZTDlVg==}
engines: {node: '>=12'}
dependencies:
'@jridgewell/sourcemap-codec': 1.4.15
rollup: ^3.25
typescript: ^4.5 || ^5.0
dependencies:
- magic-string: 0.30.3
+ magic-string: 0.30.4
rollup: 3.29.4
typescript: 5.2.2
optionalDependencies:
typescript: 5.2.2
dev: true
- /ts-node@10.9.1(@types/node@20.7.1)(typescript@5.2.2):
+ /ts-node@10.9.1(@types/node@20.7.2)(typescript@5.2.2):
resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==}
hasBin: true
peerDependencies:
'@tsconfig/node12': 1.0.11
'@tsconfig/node14': 1.0.3
'@tsconfig/node16': 1.0.4
- '@types/node': 20.7.1
+ '@types/node': 20.7.2
acorn: 8.10.0
acorn-walk: 8.2.0
arg: 4.1.3