@nestia/benchmark 7.0.0-dev.20250607 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
- import { IFetchRoute } from "@nestia/fetcher";
2
-
3
- export interface IBenchmarkEvent {
4
- metadata: IFetchRoute<any>;
5
- status: number | null;
6
- started_at: string;
7
- respond_at: string | null;
8
- completed_at: string;
9
- success: boolean;
10
- }
1
+ import { IFetchRoute } from "@nestia/fetcher";
2
+
3
+ export interface IBenchmarkEvent {
4
+ metadata: IFetchRoute<any>;
5
+ status: number | null;
6
+ started_at: string;
7
+ respond_at: string | null;
8
+ completed_at: string;
9
+ success: boolean;
10
+ }
package/src/index.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./DynamicBenchmarker";
2
- export * from "./IBenchmarkEvent";
1
+ export * from "./DynamicBenchmarker";
2
+ export * from "./IBenchmarkEvent";
@@ -1,104 +1,104 @@
1
- import os from "os";
2
-
3
- import { DynamicBenchmarker } from "../DynamicBenchmarker";
4
-
5
- export namespace DynamicBenchmarkReporter {
6
- export const markdown = (report: DynamicBenchmarker.IReport): string => {
7
- const format = (value: number | null) =>
8
- value === null ? "N/A" : (Math.floor(value * 100) / 100).toLocaleString();
9
- const head = () =>
10
- [
11
- "Type",
12
- "Count",
13
- "Success",
14
- "Mean.",
15
- "Stdev.",
16
- "Minimum",
17
- "Maximum",
18
- ].join(" | ") +
19
- "\n" +
20
- new Array(7).fill("----").join("|");
21
- const row = (title: string, s: DynamicBenchmarker.IReport.IStatistics) =>
22
- [
23
- title,
24
- s.count.toLocaleString(),
25
- s.success.toLocaleString(),
26
- format(s.mean),
27
- format(s.stdev),
28
- format(s.minimum),
29
- format(s.maximum),
30
- ].join(" | ");
31
- const line = (
32
- title: string,
33
- getter: (m: NodeJS.MemoryUsage) => number,
34
- ): string =>
35
- `line "${title}" [${report.memories.map((m) => Math.floor(getter(m.usage) / 1024 ** 2)).join(", ")}]`;
36
-
37
- return [
38
- `# Benchmark Report`,
39
- "> Generated by [`@nestia/benchmark`](https://github.com/samchon/nestia)",
40
- ``,
41
- ` - Specifications`,
42
- ` - CPU: ${os.cpus()[0].model}`,
43
- ` - RAM: ${Math.floor(os.totalmem() / 1024 / 1024 / 1024).toLocaleString()} GB`,
44
- ` - NodeJS Version: ${process.version}`,
45
- ` - Backend Server: 1 core / 1 thread`,
46
- ` - Arguments`,
47
- ` - Count: ${report.count.toLocaleString()}`,
48
- ` - Threads: ${report.threads.toLocaleString()}`,
49
- ` - Simultaneous: ${report.simultaneous.toLocaleString()}`,
50
- ` - Time`,
51
- ` - Start: ${report.started_at}`,
52
- ` - Complete: ${report.completed_at}`,
53
- ` - Elapsed: ${(new Date(report.completed_at).getTime() - new Date(report.started_at).getTime()).toLocaleString()} ms`,
54
- ``,
55
- head(),
56
- row("Total", report.statistics),
57
- "",
58
- "> Unit: milliseconds",
59
- "",
60
- "## Memory Consumptions",
61
- "```mermaid",
62
- "xychart-beta",
63
- ` x-axis "Time (second)"`,
64
- ` y-axis "Memory (MB)"`,
65
- ` ${line("Resident Set Size", (m) => m.rss)}`,
66
- ` ${line("Heap Total", (m) => m.heapTotal)}`,
67
- ` ${line("Heap Used + External", (m) => m.heapUsed + m.external)}`,
68
- ` ${line("Heap Used Only", (m) => m.heapUsed)}`,
69
- "```",
70
- "",
71
- `> - 🟦 Resident Set Size`,
72
- `> - 🟢 Heap Total`,
73
- `> - 🔴 Heap Used + External`,
74
- `> - 🟡 Heap Used Only`,
75
- "",
76
- "## Endpoints",
77
- head(),
78
- ...report.endpoints
79
- .slice()
80
- .sort((a, b) => (b.mean ?? 0) - (a.mean ?? 0))
81
- .map((endpoint) =>
82
- row(`${endpoint.method} ${endpoint.path}`, endpoint),
83
- ),
84
- "",
85
- "> Unit: milliseconds",
86
- "",
87
- "## Failures",
88
- "Method | Path | Count | Failures",
89
- "-------|------|-------|----------",
90
- ...report.endpoints
91
- .filter((e) => e.success !== e.count)
92
- .slice()
93
- .sort((a, b) => b.count - a.count)
94
- .map((e) =>
95
- [
96
- e.method,
97
- e.path,
98
- e.count.toLocaleString(),
99
- (e.count - e.success).toLocaleString(),
100
- ].join(" | "),
101
- ),
102
- ].join("\n");
103
- };
104
- }
1
+ import os from "os";
2
+
3
+ import { DynamicBenchmarker } from "../DynamicBenchmarker";
4
+
5
+ export namespace DynamicBenchmarkReporter {
6
+ export const markdown = (report: DynamicBenchmarker.IReport): string => {
7
+ const format = (value: number | null) =>
8
+ value === null ? "N/A" : (Math.floor(value * 100) / 100).toLocaleString();
9
+ const head = () =>
10
+ [
11
+ "Type",
12
+ "Count",
13
+ "Success",
14
+ "Mean.",
15
+ "Stdev.",
16
+ "Minimum",
17
+ "Maximum",
18
+ ].join(" | ") +
19
+ "\n" +
20
+ new Array(7).fill("----").join("|");
21
+ const row = (title: string, s: DynamicBenchmarker.IReport.IStatistics) =>
22
+ [
23
+ title,
24
+ s.count.toLocaleString(),
25
+ s.success.toLocaleString(),
26
+ format(s.mean),
27
+ format(s.stdev),
28
+ format(s.minimum),
29
+ format(s.maximum),
30
+ ].join(" | ");
31
+ const line = (
32
+ title: string,
33
+ getter: (m: NodeJS.MemoryUsage) => number,
34
+ ): string =>
35
+ `line "${title}" [${report.memories.map((m) => Math.floor(getter(m.usage) / 1024 ** 2)).join(", ")}]`;
36
+
37
+ return [
38
+ `# Benchmark Report`,
39
+ "> Generated by [`@nestia/benchmark`](https://github.com/samchon/nestia)",
40
+ ``,
41
+ ` - Specifications`,
42
+ ` - CPU: ${os.cpus()[0].model}`,
43
+ ` - RAM: ${Math.floor(os.totalmem() / 1024 / 1024 / 1024).toLocaleString()} GB`,
44
+ ` - NodeJS Version: ${process.version}`,
45
+ ` - Backend Server: 1 core / 1 thread`,
46
+ ` - Arguments`,
47
+ ` - Count: ${report.count.toLocaleString()}`,
48
+ ` - Threads: ${report.threads.toLocaleString()}`,
49
+ ` - Simultaneous: ${report.simultaneous.toLocaleString()}`,
50
+ ` - Time`,
51
+ ` - Start: ${report.started_at}`,
52
+ ` - Complete: ${report.completed_at}`,
53
+ ` - Elapsed: ${(new Date(report.completed_at).getTime() - new Date(report.started_at).getTime()).toLocaleString()} ms`,
54
+ ``,
55
+ head(),
56
+ row("Total", report.statistics),
57
+ "",
58
+ "> Unit: milliseconds",
59
+ "",
60
+ "## Memory Consumptions",
61
+ "```mermaid",
62
+ "xychart-beta",
63
+ ` x-axis "Time (second)"`,
64
+ ` y-axis "Memory (MB)"`,
65
+ ` ${line("Resident Set Size", (m) => m.rss)}`,
66
+ ` ${line("Heap Total", (m) => m.heapTotal)}`,
67
+ ` ${line("Heap Used + External", (m) => m.heapUsed + m.external)}`,
68
+ ` ${line("Heap Used Only", (m) => m.heapUsed)}`,
69
+ "```",
70
+ "",
71
+ `> - 🟦 Resident Set Size`,
72
+ `> - 🟢 Heap Total`,
73
+ `> - 🔴 Heap Used + External`,
74
+ `> - 🟡 Heap Used Only`,
75
+ "",
76
+ "## Endpoints",
77
+ head(),
78
+ ...report.endpoints
79
+ .slice()
80
+ .sort((a, b) => (b.mean ?? 0) - (a.mean ?? 0))
81
+ .map((endpoint) =>
82
+ row(`${endpoint.method} ${endpoint.path}`, endpoint),
83
+ ),
84
+ "",
85
+ "> Unit: milliseconds",
86
+ "",
87
+ "## Failures",
88
+ "Method | Path | Count | Failures",
89
+ "-------|------|-------|----------",
90
+ ...report.endpoints
91
+ .filter((e) => e.success !== e.count)
92
+ .slice()
93
+ .sort((a, b) => b.count - a.count)
94
+ .map((e) =>
95
+ [
96
+ e.method,
97
+ e.path,
98
+ e.count.toLocaleString(),
99
+ (e.count - e.success).toLocaleString(),
100
+ ].join(" | "),
101
+ ),
102
+ ].join("\n");
103
+ };
104
+ }
@@ -1,4 +1,4 @@
1
- export interface IBenchmarkMaster {
2
- filter: (name: string) => boolean;
3
- progress: (current: number) => void;
4
- }
1
+ export interface IBenchmarkMaster {
2
+ filter: (name: string) => boolean;
3
+ progress: (current: number) => void;
4
+ }
@@ -1,8 +1,8 @@
1
- import { IBenchmarkEvent } from "../IBenchmarkEvent";
2
-
3
- export interface IBenchmarkServant {
4
- execute(props: {
5
- count: number;
6
- simultaneous: number;
7
- }): Promise<IBenchmarkEvent[]>;
8
- }
1
+ import { IBenchmarkEvent } from "../IBenchmarkEvent";
2
+
3
+ export interface IBenchmarkServant {
4
+ execute(props: {
5
+ count: number;
6
+ simultaneous: number;
7
+ }): Promise<IBenchmarkEvent[]>;
8
+ }