Commit | Line | Data |
---|---|---|
8f01ffbe | 1 | import { writeFileSync } from 'node:fs' |
0b35a7a9 | 2 | import { env } from 'node:process' |
b9ded264 | 3 | // eslint-disable-next-line n/no-unsupported-features/node-builtins |
0804b9b4 JB |
4 | import { parseArgs } from 'node:util' |
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 | 12 | import { |
8f01ffbe | 13 | convertTatamiNgToBmf, |
b5ca7c94 | 14 | runPoolifierBenchmarkTatamiNg |
0804b9b4 | 15 | } from '../benchmarks-utils.mjs' |
cdace0e5 | 16 | |
d09b37fc | 17 | const poolSize = availableParallelism() |
cdace0e5 JB |
18 | const taskExecutions = 1 |
19 | const workerData = { | |
66f0c14c | 20 | function: TaskFunctions.factorial, |
e36fefed | 21 | taskSize: 1000 |
cdace0e5 | 22 | } |
8f01ffbe JB |
23 | const benchmarkReportFile = 'benchmark-report.json' |
24 | let benchmarkReport | |
f1c674cd | 25 | |
a6bef8d2 JB |
26 | switch ( |
27 | parseArgs({ | |
28 | args: process.argv, | |
29 | options: { | |
30 | type: { | |
31 | type: 'string', | |
32 | short: 't' | |
33 | } | |
34 | }, | |
35 | strict: true, | |
36 | allowPositionals: true | |
37 | }).values.type | |
38 | ) { | |
98f60ddd | 39 | case 'tatami-ng': |
0804b9b4 | 40 | default: |
8f01ffbe JB |
41 | benchmarkReport = convertTatamiNgToBmf( |
42 | await runPoolifierBenchmarkTatamiNg( | |
43 | 'FixedThreadPool', | |
44 | WorkerTypes.thread, | |
45 | PoolTypes.fixed, | |
46 | poolSize, | |
47 | { | |
48 | taskExecutions, | |
49 | workerData | |
50 | } | |
51 | ) | |
0804b9b4 | 52 | ) |
8f01ffbe JB |
53 | benchmarkReport = { |
54 | ...benchmarkReport, | |
55 | ...convertTatamiNgToBmf( | |
56 | await runPoolifierBenchmarkTatamiNg( | |
57 | 'DynamicThreadPool', | |
58 | WorkerTypes.thread, | |
59 | PoolTypes.dynamic, | |
60 | poolSize, | |
61 | { | |
62 | taskExecutions, | |
63 | workerData | |
64 | } | |
65 | ) | |
66 | ) | |
67 | } | |
68 | benchmarkReport = { | |
69 | ...benchmarkReport, | |
70 | ...convertTatamiNgToBmf( | |
71 | await runPoolifierBenchmarkTatamiNg( | |
72 | 'FixedClusterPool', | |
73 | WorkerTypes.cluster, | |
74 | PoolTypes.fixed, | |
75 | poolSize, | |
76 | { | |
77 | taskExecutions, | |
78 | workerData | |
79 | } | |
80 | ) | |
81 | ) | |
82 | } | |
83 | benchmarkReport = { | |
84 | ...benchmarkReport, | |
85 | ...convertTatamiNgToBmf( | |
86 | await runPoolifierBenchmarkTatamiNg( | |
87 | 'DynamicClusterPool', | |
88 | WorkerTypes.cluster, | |
89 | PoolTypes.dynamic, | |
90 | poolSize, | |
91 | { | |
92 | taskExecutions, | |
93 | workerData | |
94 | } | |
95 | ) | |
96 | ) | |
97 | } | |
98 | env.CI != null && | |
99 | writeFileSync(benchmarkReportFile, JSON.stringify(benchmarkReport)) | |
0804b9b4 JB |
100 | break |
101 | } |