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