build(deps-dev): apply updates
[poolifier.git] / benchmarks / internal / bench.mjs
CommitLineData
8f01ffbe 1import { writeFileSync } from 'node:fs'
0b35a7a9 2import { env } from 'node:process'
b9ded264 3// eslint-disable-next-line n/no-unsupported-features/node-builtins
0804b9b4
JB
4import { parseArgs } from 'node:util'
5
d09b37fc 6import {
ded253e2 7 availableParallelism,
d9d8c14e 8 PoolTypes,
3a502712 9 WorkerTypes,
d09b37fc 10} from '../../lib/index.mjs'
d35e5717 11import { TaskFunctions } from '../benchmarks-types.cjs'
0804b9b4 12import {
8f01ffbe 13 convertTatamiNgToBmf,
3a502712 14 runPoolifierBenchmarkTatamiNg,
0804b9b4 15} from '../benchmarks-utils.mjs'
cdace0e5 16
d09b37fc 17const poolSize = availableParallelism()
cdace0e5
JB
18const taskExecutions = 1
19const workerData = {
66f0c14c 20 function: TaskFunctions.factorial,
3a502712 21 taskSize: 1000,
cdace0e5 22}
8f01ffbe
JB
23const benchmarkReportFile = 'benchmark-report.json'
24let benchmarkReport
f1c674cd 25
a6bef8d2
JB
26switch (
27 parseArgs({
28 args: process.argv,
29 options: {
30 type: {
31 type: 'string',
3a502712
JB
32 short: 't',
33 },
a6bef8d2
JB
34 },
35 strict: true,
3a502712 36 allowPositionals: true,
a6bef8d2
JB
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,
3a502712 49 workerData,
8f01ffbe
JB
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,
3a502712 63 workerData,
8f01ffbe
JB
64 }
65 )
3a502712 66 ),
8f01ffbe
JB
67 }
68 benchmarkReport = {
69 ...benchmarkReport,
70 ...convertTatamiNgToBmf(
71 await runPoolifierBenchmarkTatamiNg(
72 'FixedClusterPool',
73 WorkerTypes.cluster,
74 PoolTypes.fixed,
75 poolSize,
76 {
77 taskExecutions,
3a502712 78 workerData,
8f01ffbe
JB
79 }
80 )
3a502712 81 ),
8f01ffbe
JB
82 }
83 benchmarkReport = {
84 ...benchmarkReport,
85 ...convertTatamiNgToBmf(
86 await runPoolifierBenchmarkTatamiNg(
87 'DynamicClusterPool',
88 WorkerTypes.cluster,
89 PoolTypes.dynamic,
90 poolSize,
91 {
92 taskExecutions,
3a502712 93 workerData,
8f01ffbe
JB
94 }
95 )
3a502712 96 ),
8f01ffbe 97 }
3a502712 98 // eslint-disable-next-line @typescript-eslint/no-unused-expressions
8f01ffbe
JB
99 env.CI != null &&
100 writeFileSync(benchmarkReportFile, JSON.stringify(benchmarkReport))
0804b9b4
JB
101 break
102}