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