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