-import assert from 'node:assert'
-import Benchmark from 'benchmark'
+import { exit } from 'node:process'
import {
PoolTypes,
- WorkerChoiceStrategies,
WorkerTypes,
availableParallelism
} from '../../lib/index.mjs'
-import { TaskFunctions } from '../benchmarks-types.mjs'
-import {
- LIST_FORMATTER,
- buildPoolifierPool,
- getPoolImplementationName,
- runPoolifierTest
-} from '../benchmarks-utils.mjs'
+import { TaskFunctions } from '../benchmarks-types.cjs'
+import { runPoolifierPoolBenchmark } from '../benchmarks-utils.cjs'
const poolSize = availableParallelism()
-const fixedThreadPool = buildPoolifierPool(
- WorkerTypes.thread,
- PoolTypes.fixed,
- poolSize
-)
-
const taskExecutions = 1
const workerData = {
function: TaskFunctions.jsonIntegerSerialization,
taskSize: 1000
}
-const poolifierSuite = new Benchmark.Suite('Poolifier')
+// FixedThreadPool
+await runPoolifierPoolBenchmark(
+ 'FixedThreadPool',
+ WorkerTypes.thread,
+ PoolTypes.fixed,
+ poolSize,
+ {
+ taskExecutions,
+ workerData
+ }
+)
-for (const pool of [fixedThreadPool]) {
- for (const workerChoiceStrategy of Object.values(WorkerChoiceStrategies)) {
- for (const enableTasksQueue of [false, true]) {
- poolifierSuite.add(
- `${getPoolImplementationName(pool)}|${workerChoiceStrategy}|${
- enableTasksQueue ? 'with' : 'without'
- } tasks queue`,
- async () => {
- pool.setWorkerChoiceStrategy(workerChoiceStrategy)
- pool.enableTasksQueue(enableTasksQueue)
- assert.strictEqual(
- pool.opts.workerChoiceStrategy,
- workerChoiceStrategy
- )
- assert.strictEqual(pool.opts.enableTasksQueue, enableTasksQueue)
- await runPoolifierTest(pool, {
- taskExecutions,
- workerData
- })
- }
- )
- }
+// DynamicThreadPool
+await runPoolifierPoolBenchmark(
+ 'DynamicThreadPool',
+ WorkerTypes.thread,
+ PoolTypes.dynamic,
+ poolSize,
+ {
+ taskExecutions,
+ workerData
}
-}
+)
+
+// FixedClusterPool
+await runPoolifierPoolBenchmark(
+ 'FixedClusterPool',
+ WorkerTypes.cluster,
+ PoolTypes.fixed,
+ poolSize,
+ {
+ taskExecutions,
+ workerData
+ }
+)
+
+// DynamicClusterPool
+await runPoolifierPoolBenchmark(
+ 'DynamicClusterPool',
+ WorkerTypes.cluster,
+ PoolTypes.dynamic,
+ poolSize,
+ {
+ taskExecutions,
+ workerData
+ }
+)
-poolifierSuite
- .on('cycle', event => {
- console.info(event.target.toString())
- })
- .on('complete', async function () {
- console.info(
- 'Fastest is ' + LIST_FORMATTER.format(this.filter('fastest').map('name'))
- )
- await fixedThreadPool.destroy()
- })
- .run({ async: true })
+exit()