1 import { strictEqual } from 'node:assert'
3 import { bench, clear, group, run } from 'tatami-ng'
12 WorkerChoiceStrategies,
14 } from '../lib/index.mjs'
15 import { executeTaskFunction } from './benchmarks-utils.cjs'
17 const buildPoolifierPool = (workerType, poolType, poolSize, poolOptions) => {
21 case WorkerTypes.thread:
22 return new FixedThreadPool(
24 './benchmarks/internal/thread-worker.mjs',
27 case WorkerTypes.cluster:
28 return new FixedClusterPool(
30 './benchmarks/internal/cluster-worker.cjs',
35 case PoolTypes.dynamic:
37 case WorkerTypes.thread:
38 return new DynamicThreadPool(
39 Math.floor(poolSize / 2),
41 './benchmarks/internal/thread-worker.mjs',
44 case WorkerTypes.cluster:
45 return new DynamicClusterPool(
46 Math.floor(poolSize / 2),
48 './benchmarks/internal/cluster-worker.cjs',
56 const runPoolifierPool = async (pool, { taskExecutions, workerData }) => {
57 for (let i = 1; i <= taskExecutions; i++) {
58 await pool.execute(workerData)
62 export const runPoolifierBenchmarkTatamiNg = async (
67 { taskExecutions, workerData }
70 const pool = buildPoolifierPool(workerType, poolType, poolSize)
71 for (const workerChoiceStrategy of Object.values(WorkerChoiceStrategies)) {
72 for (const enableTasksQueue of [false, true]) {
73 if (workerChoiceStrategy === WorkerChoiceStrategies.FAIR_SHARE) {
74 for (const measurement of [Measurements.runTime, Measurements.elu]) {
77 `${name} with ${workerChoiceStrategy}, with ${measurement} and ${
78 enableTasksQueue ? 'with' : 'without'
81 await runPoolifierPool(pool, {
88 pool.setWorkerChoiceStrategy(workerChoiceStrategy, {
91 pool.enableTasksQueue(enableTasksQueue)
93 pool.opts.workerChoiceStrategy,
96 strictEqual(pool.opts.enableTasksQueue, enableTasksQueue)
98 pool.opts.workerChoiceStrategyOptions.measurement,
109 `${name} with ${workerChoiceStrategy} and ${
110 enableTasksQueue ? 'with' : 'without'
113 await runPoolifierPool(pool, {
120 pool.setWorkerChoiceStrategy(workerChoiceStrategy)
121 pool.enableTasksQueue(enableTasksQueue)
123 pool.opts.workerChoiceStrategy,
126 strictEqual(pool.opts.enableTasksQueue, enableTasksQueue)
134 const report = await run()
143 export const convertTatamiNgToBmf = report => {
144 return report.benchmarks
145 .map(({ name, stats }) => {
150 lower_value: stats?.min,
151 upper_value: stats?.max,
159 .reduce((obj, item) => Object.assign(obj, item), {})
162 export { executeTaskFunction }