refactor: cleanup object destructuration in examples
[poolifier.git] / benchmarks / internal / bench.mjs
CommitLineData
149fdbb9 1import { add, complete, cycle, save, suite } from 'benny'
d09b37fc 2import {
d9d8c14e
JB
3 Measurements,
4 PoolTypes,
d09b37fc 5 WorkerChoiceStrategies,
d9d8c14e 6 WorkerTypes,
d09b37fc
JB
7 availableParallelism
8} from '../../lib/index.mjs'
dbca3be9 9import { TaskFunctions } from '../benchmarks-types.mjs'
8f810074 10import { buildPool, runTest } from '../benchmarks-utils.mjs'
cdace0e5 11
d09b37fc 12const poolSize = availableParallelism()
149fdbb9
JB
13const pools = []
14for (const poolType of Object.values(PoolTypes)) {
15 for (const workerType of Object.values(WorkerTypes)) {
23a6c28d
JB
16 if (workerType === WorkerTypes.cluster) {
17 continue
18 }
149fdbb9 19 for (const workerChoiceStrategy of Object.values(WorkerChoiceStrategies)) {
d9d8c14e
JB
20 for (const enableTasksQueue of [false, true]) {
21 if (workerChoiceStrategy === WorkerChoiceStrategies.FAIR_SHARE) {
22 for (const measurement of [Measurements.runTime, Measurements.elu]) {
d9d8c14e
JB
23 pools.push([
24 `${poolType}|${workerType}|${workerChoiceStrategy}|tasks queue:${enableTasksQueue}|measurement:${measurement}`,
6bec21ed
JB
25 buildPool(workerType, poolType, poolSize, {
26 workerChoiceStrategy,
27 workerChoiceStrategyOptions: {
28 measurement
29 },
30 enableTasksQueue
31 })
d9d8c14e
JB
32 ])
33 }
34 } else {
d9d8c14e
JB
35 pools.push([
36 `${poolType}|${workerType}|${workerChoiceStrategy}|tasks queue:${enableTasksQueue}`,
6bec21ed
JB
37 buildPool(workerType, poolType, poolSize, {
38 workerChoiceStrategy,
39 enableTasksQueue
40 })
d9d8c14e
JB
41 ])
42 }
149fdbb9
JB
43 }
44 }
45 }
46}
0819631d 47
cdace0e5
JB
48const taskExecutions = 1
49const workerData = {
dbca3be9 50 function: TaskFunctions.jsonIntegerSerialization,
cdace0e5
JB
51 taskSize: 1000
52}
8ebe6c30 53const addPools = (pools) =>
149fdbb9
JB
54 pools.map(([name, pool]) => {
55 return add(name, async () => {
56 await runTest(pool, {
57 taskExecutions,
58 workerData
59 })
60 })
61 })
325f50bc 62
ca6c7d70
JB
63const resultsFile = 'poolifier'
64const resultsFolder = 'benchmarks/internal/results'
149fdbb9 65suite(
ca6c7d70 66 'Poolifier',
149fdbb9
JB
67 ...addPools(pools),
68 cycle(),
69 complete(),
70 save({
ca6c7d70
JB
71 file: resultsFile,
72 folder: resultsFolder,
73 format: 'json',
74 details: true
75 }),
149fdbb9 76 save({
ca6c7d70
JB
77 file: resultsFile,
78 folder: resultsFolder,
79 format: 'chart.html',
80 details: true
81 }),
149fdbb9 82 save({
ca6c7d70
JB
83 file: resultsFile,
84 folder: resultsFolder,
85 format: 'table.html',
86 details: true
87 })
88)
18cac485
JB
89 .then(() => {
90 // eslint-disable-next-line n/no-process-exit
91 return process.exit()
92 })
8ebe6c30 93 .catch((err) => console.error(err))