case WorkerTypes.thread:
return new FixedThreadPool(
poolSize,
- './benchmarks/internal/thread-worker.js',
+ './benchmarks/internal/thread-worker.mjs',
poolOptions
)
case WorkerTypes.cluster:
return new FixedClusterPool(
poolSize,
- './benchmarks/internal/cluster-worker.js',
+ './benchmarks/internal/cluster-worker.mjs',
poolOptions
)
}
return new DynamicThreadPool(
poolSize / 2,
poolSize * 3,
- './benchmarks/internal/thread-worker.js',
+ './benchmarks/internal/thread-worker.mjs',
poolOptions
)
case WorkerTypes.cluster:
return new DynamicClusterPool(
poolSize / 2,
poolSize * 3,
- './benchmarks/internal/cluster-worker.js',
+ './benchmarks/internal/cluster-worker.mjs',
poolOptions
)
}
-const Benchmark = require('benny')
-const { WorkerChoiceStrategies } = require('../../lib')
-const {
- PoolTypes,
- WorkerFunctions,
- WorkerTypes
-} = require('../benchmarks-types')
-const { buildPool, runTest } = require('../benchmarks-utils')
+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'
const poolSize = 30
const taskExecutions = 1
-'use strict'
-const { isMaster } = require('cluster')
-const { ClusterWorker } = require('../../lib')
-const { executeWorkerFunction } = require('../benchmarks-utils')
-const { WorkerFunctions } = require('../benchmarks-types')
+import { isMaster } from 'cluster'
+import { ClusterWorker } from '../../lib/index.mjs'
+import { executeWorkerFunction } from '../benchmarks-utils.js'
+import { WorkerFunctions } from '../benchmarks-types.js'
const debug = false
return { ok: 1 }
}
-module.exports = new ClusterWorker(yourFunction)
+export default new ClusterWorker(yourFunction)
+++ /dev/null
-'use strict'
-const { isMainThread } = require('worker_threads')
-const { ThreadWorker } = require('../../lib')
-const { executeWorkerFunction } = require('../benchmarks-utils')
-const { WorkerFunctions } = require('../benchmarks-types')
-
-const debug = false
-
-function yourFunction (data) {
- data = data || {}
- data.function = data.function || WorkerFunctions.jsonIntegerSerialization
- executeWorkerFunction(data)
- debug === true && console.debug('This is the main thread ' + isMainThread)
- return { ok: 1 }
-}
-
-module.exports = new ThreadWorker(yourFunction)
--- /dev/null
+import { isMainThread } from 'worker_threads'
+import { ThreadWorker } from '../../lib/index.mjs'
+import { executeWorkerFunction } from '../benchmarks-utils.js'
+import { WorkerFunctions } from '../benchmarks-types.js'
+
+const debug = false
+
+function yourFunction (data) {
+ data = data || {}
+ data.function = data.function || WorkerFunctions.jsonIntegerSerialization
+ executeWorkerFunction(data)
+ debug === true && console.debug('This is the main thread ' + isMainThread)
+ return { ok: 1 }
+}
+
+export default new ThreadWorker(yourFunction)
"build:analyze": "rollup --config --environment ANALYZE,BUILD:development",
"build:typedoc": "rollup --config --environment DOCUMENTATION,BUILD:development",
"build:prod": "rollup --config",
- "benchmark": "pnpm build && node -r source-map-support/register benchmarks/internal/bench.js",
- "benchmark:debug": "pnpm build && node -r source-map-support/register --inspect benchmarks/internal/bench.js",
- "benchmark:prod": "pnpm build:prod && node -r source-map-support/register benchmarks/internal/bench.js",
+ "benchmark": "pnpm build && node -r source-map-support/register benchmarks/internal/bench.mjs",
+ "benchmark:debug": "pnpm build && node -r source-map-support/register --inspect benchmarks/internal/bench.mjs",
+ "benchmark:prod": "pnpm build:prod && node -r source-map-support/register benchmarks/internal/bench.mjs",
"test": "pnpm build && c8 mocha 'tests/**/*.test.js'",
"test:debug": "pnpm build && mocha --no-parallel --inspect 'tests/**/*.test.js'",
"coverage": "c8 report --reporter=lcov",
*/
protected lastTaskTimestamp!: number
/**
- * Performance statistics computation.
+ * Performance statistics computation requirements.
*/
protected statistics!: WorkerStatistics
/**
}
private beginTaskPerformance (): TaskPerformance {
+ this.checkStatistics()
return {
timestamp: performance.now(),
...(this.statistics.elu && { elu: performance.eventLoopUtilization() })
private endTaskPerformance (
taskPerformance: TaskPerformance
): TaskPerformance {
+ this.checkStatistics()
return {
...taskPerformance,
...(this.statistics.runTime && {
})
}
}
+
+ private checkStatistics (): void {
+ if (this.statistics == null) {
+ throw new Error('Performance statistics computation requirements not set')
+ }
+ }
}