build(deps-dev): apply updates
[poolifier.git] / benchmarks / internal / bench.mjs
1 import { exit } from 'node:process'
2 // eslint-disable-next-line n/no-unsupported-features/node-builtins
3 import { parseArgs } from 'node:util'
4
5 import {
6 availableParallelism,
7 PoolTypes,
8 WorkerTypes
9 } from '../../lib/index.mjs'
10 import { TaskFunctions } from '../benchmarks-types.cjs'
11 import {
12 runPoolifierBenchmarkBenchmarkJsSuite,
13 runPoolifierBenchmarkTatamiNg
14 } from '../benchmarks-utils.mjs'
15
16 const poolSize = availableParallelism()
17 const taskExecutions = 1
18 const workerData = {
19 function: TaskFunctions.factorial,
20 taskSize: 50000
21 }
22
23 switch (
24 parseArgs({
25 args: process.argv,
26 options: {
27 type: {
28 type: 'string',
29 short: 't'
30 }
31 },
32 strict: true,
33 allowPositionals: true
34 }).values.type
35 ) {
36 case 'tatami-ng':
37 await runPoolifierBenchmarkTatamiNg(
38 'FixedThreadPool',
39 WorkerTypes.thread,
40 PoolTypes.fixed,
41 poolSize,
42 {
43 taskExecutions,
44 workerData
45 }
46 )
47 await runPoolifierBenchmarkTatamiNg(
48 'DynamicThreadPool',
49 WorkerTypes.thread,
50 PoolTypes.dynamic,
51 poolSize,
52 {
53 taskExecutions,
54 workerData
55 }
56 )
57 await runPoolifierBenchmarkTatamiNg(
58 'FixedClusterPool',
59 WorkerTypes.cluster,
60 PoolTypes.fixed,
61 poolSize,
62 {
63 taskExecutions,
64 workerData
65 }
66 )
67 await runPoolifierBenchmarkTatamiNg(
68 'DynamicClusterPool',
69 WorkerTypes.cluster,
70 PoolTypes.dynamic,
71 poolSize,
72 {
73 taskExecutions,
74 workerData
75 }
76 )
77 break
78 case 'benchmark.js':
79 default:
80 await runPoolifierBenchmarkBenchmarkJsSuite(
81 'FixedThreadPool',
82 WorkerTypes.thread,
83 PoolTypes.fixed,
84 poolSize,
85 {
86 taskExecutions,
87 workerData
88 }
89 )
90 await runPoolifierBenchmarkBenchmarkJsSuite(
91 'DynamicThreadPool',
92 WorkerTypes.thread,
93 PoolTypes.dynamic,
94 poolSize,
95 {
96 taskExecutions,
97 workerData
98 }
99 )
100 await runPoolifierBenchmarkBenchmarkJsSuite(
101 'FixedClusterPool',
102 WorkerTypes.cluster,
103 PoolTypes.fixed,
104 poolSize,
105 {
106 taskExecutions,
107 workerData
108 }
109 )
110 await runPoolifierBenchmarkBenchmarkJsSuite(
111 'DynamicClusterPool',
112 WorkerTypes.cluster,
113 PoolTypes.dynamic,
114 poolSize,
115 {
116 taskExecutions,
117 workerData
118 }
119 )
120 break
121 }
122
123 exit()