Skip to content

Commit

Permalink
Merge pull request #971 from samchon/feature/memory
Browse files Browse the repository at this point in the history
Make memory consumption benchmark much detaily.
  • Loading branch information
samchon authored Jul 26, 2024
2 parents c354da5 + 315171a commit 62794ee
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/benchmark/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/benchmark",
"version": "0.2.0",
"version": "0.2.3",
"description": "NestJS Performance Benchmark Program",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
33 changes: 22 additions & 11 deletions packages/benchmark/src/internal/DynamicBenchmarkReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export namespace DynamicBenchmarWriter {
export const markdown = (report: DynamicBenchmarker.IReport): string => {
const format = (value: number | null) =>
value === null ? "N/A" : (Math.floor(value * 100) / 100).toLocaleString();
const writeHead = () =>
const head = () =>
[
"Type",
"Count",
Expand All @@ -18,10 +18,7 @@ export namespace DynamicBenchmarWriter {
].join(" | ") +
"\n" +
new Array(7).fill("----").join("|");
const writeRow = (
title: string,
s: DynamicBenchmarker.IReport.IStatistics,
) =>
const row = (title: string, s: DynamicBenchmarker.IReport.IStatistics) =>
[
title,
s.count.toLocaleString(),
Expand All @@ -31,6 +28,12 @@ export namespace DynamicBenchmarWriter {
format(s.minimum),
format(s.maximum),
].join(" | ");
const line = (
title: string,
getter: (m: NodeJS.MemoryUsage) => number,
): string =>
`line "${title}" [${report.memories.map((m) => Math.floor(getter(m.usage) / 1024 ** 2)).join(", ")}]`;

return [
`# Benchmark Report`,
"> Generated by [`@nestia/benchmark`](https://github.com/samchon/nestia)",
Expand All @@ -49,26 +52,34 @@ export namespace DynamicBenchmarWriter {
` - Complete: ${report.completed_at}`,
` - Elapsed: ${(new Date(report.completed_at).getTime() - new Date(report.started_at).getTime()).toLocaleString()} ms`,
``,
writeHead(),
writeRow("Total", report.statistics),
head(),
row("Total", report.statistics),
"",
"> Unit: milliseconds",
"",
"## Memory Usage",
"## Memory Consumptions",
"```mermaid",
"xychart-beta",
` x-axis "Time (second)"`,
` y-axis "Memory (MB)"`,
` line [${report.memories.map((m) => Math.floor((m.usage.heapUsed + m.usage.external) / 1024 ** 2)).join(", ")}]`,
` ${line("Resident Set Size", (m) => m.rss)}`,
` ${line("Heap Total", (m) => m.heapTotal)}`,
` ${line("Heap Used + External", (m) => m.heapUsed + m.external)}`,
` ${line("Heap Used Only", (m) => m.heapUsed)}`,
"```",
"",
`> - 🟦 Resident Set Size`,
`> - 🟢 Heap Total`,
`> - 🔴 Heap Used + External`,
`> - 🟡 Heap Used Only`,
"",
"## Endpoints",
writeHead(),
head(),
...report.endpoints
.slice()
.sort((a, b) => (b.mean ?? 0) - (a.mean ?? 0))
.map((endpoint) =>
writeRow(`${endpoint.method} ${endpoint.path}`, endpoint),
row(`${endpoint.method} ${endpoint.path}`, endpoint),
),
"",
"> Unit: milliseconds",
Expand Down
4 changes: 2 additions & 2 deletions packages/migrate/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/migrate",
"version": "0.15.1",
"version": "0.15.2",
"description": "Migration program from swagger to NestJS",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -36,7 +36,7 @@
},
"homepage": "https://nestia.io",
"devDependencies": {
"@nestia/benchmark": "^0.2.0",
"@nestia/benchmark": "^0.2.2",
"@nestia/core": "^3.8.1",
"@nestia/e2e": "^0.7.0",
"@nestia/fetcher": "^3.8.1",
Expand Down
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@mui/icons-material": "5.15.6",
"@mui/material": "5.15.6",
"@mui/system": "5.15.6",
"@nestia/migrate": "^0.15.0",
"@nestia/migrate": "^0.15.2",
"@samchon/openapi": "^0.4.2",
"@stackblitz/sdk": "^1.9.0",
"js-yaml": "^4.1.0",
Expand Down

0 comments on commit 62794ee

Please sign in to comment.