]> Piment Noir Git Repositories - poolifier.git/blob - benchmarks/internal/bench.mjs
e24240c6ea5932a114ac9f4faf45424228afeedf
[poolifier.git] / benchmarks / internal / bench.mjs
1 import { writeFileSync } from 'node:fs'
2 import { env } from 'node:process'
3 import { parseArgs } from 'node:util'
4 import { bmf } from 'tatami-ng'
5
6 import {
7 availableParallelism,
8 PoolTypes,
9 WorkerTypes,
10 } from '../../lib/index.mjs'
11 import { TaskFunctions } from '../benchmarks-types.cjs'
12 import { runPoolifierBenchmarkTatamiNg } from '../benchmarks-utils.mjs'
13
14 const poolSize = availableParallelism()
15 const taskExecutions = 1
16 const workerData = {
17 function: TaskFunctions.factorial,
18 taskSize: 1000,
19 }
20 const benchmarkReportFile = 'benchmark-report.json'
21 let benchmarkReport
22
23 switch (
24 parseArgs({
25 allowPositionals: true,
26 args: process.argv,
27 options: {
28 type: {
29 short: 't',
30 type: 'string',
31 },
32 },
33 strict: true,
34 }).values.type
35 ) {
36 case 'tatami-ng':
37 default:
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',
53 WorkerTypes.thread,
54 PoolTypes.dynamic,
55 poolSize,
56 bmf,
57 {
58 taskExecutions,
59 workerData,
60 }
61 )),
62 }
63 benchmarkReport = {
64 ...benchmarkReport,
65 ...(await runPoolifierBenchmarkTatamiNg(
66 'FixedClusterPool',
67 WorkerTypes.cluster,
68 PoolTypes.fixed,
69 poolSize,
70 bmf,
71 {
72 taskExecutions,
73 workerData,
74 }
75 )),
76 }
77 benchmarkReport = {
78 ...benchmarkReport,
79 ...(await runPoolifierBenchmarkTatamiNg(
80 'DynamicClusterPool',
81 WorkerTypes.cluster,
82 PoolTypes.dynamic,
83 poolSize,
84 bmf,
85 {
86 taskExecutions,
87 workerData,
88 }
89 )),
90 }
91 // eslint-disable-next-line @typescript-eslint/no-unused-expressions
92 env.CI != null &&
93 writeFileSync(benchmarkReportFile, JSON.stringify(benchmarkReport))
94 break
95 }