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