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 | let fixedThreadPool |
25 | let dynamicThreadPool | |
26 | let fixedClusterPool | |
27 | let dynamicClusterPool | |
a6bef8d2 JB |
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 | ) { | |
0804b9b4 JB |
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 runPoolifierBenchmarkBenchmarkJs( | |
91 | 'FixedThreadPool', | |
92 | WorkerTypes.thread, | |
93 | PoolTypes.fixed, | |
94 | poolSize, | |
95 | { | |
96 | taskExecutions, | |
97 | workerData | |
98 | } | |
99 | ) | |
100 | await runPoolifierBenchmarkBenchmarkJs( | |
101 | 'DynamicThreadPool', | |
102 | WorkerTypes.thread, | |
103 | PoolTypes.dynamic, | |
104 | poolSize, | |
105 | { | |
106 | taskExecutions, | |
107 | workerData | |
108 | } | |
109 | ) | |
110 | await runPoolifierBenchmarkBenchmarkJs( | |
111 | 'FixedClusterPool', | |
112 | WorkerTypes.cluster, | |
113 | PoolTypes.fixed, | |
114 | poolSize, | |
115 | { | |
116 | taskExecutions, | |
117 | workerData | |
118 | } | |
119 | ) | |
120 | await runPoolifierBenchmarkBenchmarkJs( | |
121 | 'DynamicClusterPool', | |
122 | WorkerTypes.cluster, | |
123 | PoolTypes.dynamic, | |
124 | poolSize, | |
125 | { | |
126 | taskExecutions, | |
127 | workerData | |
128 | } | |
129 | ) | |
130 | break | |
131 | } | |
00a2ffdb JB |
132 | |
133 | exit() |