From 5e4292a9848212bcef44168b1617554ba6c3d698 Mon Sep 17 00:00:00 2001 From: Resham Pokhrel Date: Mon, 15 Jun 2026 00:55:24 -0500 Subject: [PATCH 01/11] Updates write snapshot to support report-table feature --- .../js-x-ray/benchmark/write-snapshot.ts | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/workspaces/js-x-ray/benchmark/write-snapshot.ts b/workspaces/js-x-ray/benchmark/write-snapshot.ts index 028a4b49..7a430e47 100644 --- a/workspaces/js-x-ray/benchmark/write-snapshot.ts +++ b/workspaces/js-x-ray/benchmark/write-snapshot.ts @@ -5,6 +5,7 @@ import { writeFileSync } from "node:fs"; import { benchmark } from "./bench.ts"; const kReportURL = new URL("report.json", import.meta.url); +const kReportMarkdownURL = new URL("report.md", import.meta.url); const results = await benchmark(); @@ -18,6 +19,7 @@ const relevantResults = { if (!trial.stats) { return []; } + const { samples, debug, ...rest } = trial.stats; return { @@ -30,3 +32,78 @@ const relevantResults = { }; writeFileSync(kReportURL, JSON.stringify(relevantResults, null, 2)); + +// Human-readable snapshot as a Markdown table. +writeFileSync(kReportMarkdownURL, toMarkdown(relevantResults)) + +/** + * mitata reports timings in nanoseconds. Picks the most readable unit. + */ +function formatDuration(nanoseconds: number): string { + if (nanoseconds < 1_000) { + return `${nanoseconds.toFixed(2)} ns`; + } + if (nanoseconds < 1_000_000) { + return `${(nanoseconds / 1_000).toFixed(2)} µs`; + } + if (nanoseconds < 1_000_000_000) { + return `${(nanoseconds / 1_000_000).toFixed(2)} ms`; + } + + return `${(nanoseconds / 1_000_000_000).toFixed(2)} s`; +} + +/** + * heap stats are reported in bytes. + */ +function formatBytes(bytes: number): string { + if (bytes < 1_024) { + return `${bytes.toFixed(0)} B`; + } + if (bytes < 1_024 ** 2) { + return `${(bytes / 1_024).toFixed(2)} KB`; + } + if (bytes < 1_024 ** 3) { + return `${(bytes / 1_024 ** 2).toFixed(2)} MB`; + } + + return `${(bytes / 1_024 ** 3).toFixed(2)} GB`; +} + +function toMarkdown(report: typeof relevantResults): string { + const header = [ + "Benchmark", "min", "max", "p25", "p50", "p75", "p99", "p999", "avg", "samples", "heap (avg)", "gc (avg)" + ]; + + const lines = [ + "# Benchmark Report", + "", + `- **Timestamp:** ${report.timestamp}`, + `- **Runtime:** ${report.runtime}`, + `- **CPU:** ${report.cpu.name} (~${report.cpu.freq.toFixed(2)} GHz)`, + "", + `| ${header.join(" | ")} |`, + `| ${header.map(() => "---").join(" | ")} |` + ]; + + for (const { name, stats } of report.benchmarks) { + const row = [ + name, + formatDuration(stats.min), + formatDuration(stats.max), + formatDuration(stats.p25), + formatDuration(stats.p50), + formatDuration(stats.p75), + formatDuration(stats.p99), + formatDuration(stats.p999), + formatDuration(stats.avg), + String(stats.ticks), + stats.heap ? formatBytes(stats.heap.avg) : "—", + stats.gc ? formatDuration(stats.gc.avg) : "—" + ]; + + lines.push(`| ${row.join(" | ")} |`); + } + + return lines.join("\n") + "\n"; +} \ No newline at end of file From 16e58efcbe8d55e43d750bbe9190d9f358a62e97 Mon Sep 17 00:00:00 2001 From: Resham Pokhrel Date: Mon, 15 Jun 2026 00:56:11 -0500 Subject: [PATCH 02/11] Updates existing json report and adds new table report --- workspaces/js-x-ray/benchmark/report.json | 338 +++++++++++----------- workspaces/js-x-ray/benchmark/report.md | 19 ++ 2 files changed, 188 insertions(+), 169 deletions(-) create mode 100644 workspaces/js-x-ray/benchmark/report.md diff --git a/workspaces/js-x-ray/benchmark/report.json b/workspaces/js-x-ray/benchmark/report.json index 6d136049..de67bc66 100644 --- a/workspaces/js-x-ray/benchmark/report.json +++ b/workspaces/js-x-ray/benchmark/report.json @@ -1,219 +1,219 @@ { - "timestamp": "2026-05-31T02:15:13.460Z", + "timestamp": "2026-06-15T05:54:25.799Z", "runtime": "node", "cpu": { - "name": "AMD EPYC 9V74 80-Core Processor", - "freq": 2.7471334664153297 + "name": "unknown", + "freq": 3.0572688134078336 }, "benchmarks": [ { "stats": { "kind": "fn", - "min": 183105, - "max": 1147855, - "p25": 214843, - "p50": 244467, - "p75": 352250, - "p99": 701234, - "p999": 1014545, - "avg": 291370.8957286432, - "ticks": 2388, + "min": 232292, + "max": 971250, + "p25": 243959, + "p50": 256125, + "p75": 270625, + "p99": 466125, + "p999": 819459, + "avg": 267252.82290076336, + "ticks": 2620, "heap": { - "_": 1910, - "total": 510270624, - "min": 3552, - "max": 2654200, - "avg": 267157.39476439793 + "_": 2037, + "total": 557137848, + "min": 1944, + "max": 2619656, + "avg": 273509.0073637703 } }, "args": {}, - "name": "Small File (jscrush.js - 1.03KB)" + "name": "Small File (jscrush.js - 1.06KB)" }, { "stats": { "kind": "fn", - "min": 506141, - "max": 2216802, - "p25": 562886, - "p50": 610708, - "p75": 863087, - "p99": 1313024, - "p999": 1939304, - "avg": 705367.7884615385, - "ticks": 988, + "min": 590125, + "max": 1603791, + "p25": 623584, + "p50": 638042, + "p75": 655792, + "p99": 1021958, + "p999": 1200959, + "avg": 655344.6476101219, + "ticks": 1067, "heap": { - "_": 805, - "total": 390169824, - "min": 728, - "max": 2189064, - "avg": 484683.01118012425 + "_": 937, + "total": 414151968, + "min": 336, + "max": 3387600, + "avg": 441997.83137673425 } }, "args": {}, - "name": "Small File (npm-audit.js - 1.46KB)" + "name": "Small File (npm-audit.js - 1.51KB)" }, { "stats": { "kind": "fn", - "min": 1499955, - "max": 3834603, - "p25": 1586144, - "p50": 1658173, - "p75": 1987717, - "p99": 3077856, - "p999": 3414622, - "avg": 1837781.1909814323, - "ticks": 377, + "min": 1482750, + "max": 3286333, + "p25": 1510708, + "p50": 1530750, + "p75": 1574541, + "p99": 2704542, + "p999": 3038750, + "avg": 1593130.360091743, + "ticks": 436, "heap": { - "_": 369, - "total": 259100864, - "min": 41664, - "max": 2024536, - "avg": 702170.3631436315 + "_": 428, + "total": 293069656, + "min": 21064, + "max": 1965032, + "avg": 684742.1869158879 } }, "args": {}, - "name": "Small File (forbes-skimmer.js - 2.15KB)" + "name": "Small File (forbes-skimmer.js - 2.20KB)" }, { "stats": { "kind": "fn", - "min": 1341766, - "max": 4508005, - "p25": 1421306, - "p50": 1530881, - "p75": 1821729, - "p99": 3333930, - "p999": 4413593, - "avg": 1696185.4152334153, - "ticks": 407, + "min": 1251708, + "max": 2998084, + "p25": 1289750, + "p50": 1323833, + "p75": 1378292, + "p99": 2599834, + "p999": 2821292, + "avg": 1386856.832, + "ticks": 500, "heap": { - "_": 395, - "total": 283735208, - "min": 85408, - "max": 2429176, - "avg": 718316.982278481 + "_": 487, + "total": 350886992, + "min": 9672, + "max": 2624600, + "avg": 720507.1704312115 } }, "args": {}, - "name": "Small File (rate-map.js - 2.21KB)" + "name": "Small File (rate-map.js - 2.30KB)" }, { "stats": { "kind": "fn", - "min": 1465161.9999980927, - "max": 4237409, - "p25": 1540856, - "p50": 1684772, - "p75": 1992725, - "p99": 3112839, - "p999": 3596565, - "avg": 1827438.6392573146, - "ticks": 377, + "min": 1743584, + "max": 5401708, + "p25": 1827209, + "p50": 1918917, + "p75": 2095458, + "p99": 3525042, + "p999": 5155291, + "avg": 2029107.8609467456, + "ticks": 338, "heap": { - "_": 370, - "total": 346951592, - "min": 1352, - "max": 2411688, - "avg": 937707.0054054054 + "_": 333, + "total": 303764776, + "min": 11432, + "max": 3204304, + "avg": 912206.5345345346 } }, "args": {}, - "name": "Small File (event-stream.js - 3.76KB)" + "name": "Small File (event-stream.js - 3.84KB)" }, { "stats": { "kind": "fn", - "min": 1058901, - "max": 2879427, - "p25": 1131230, - "p50": 1231591, - "p75": 1407035, - "p99": 2127117, - "p999": 2798075.0000009537, - "avg": 1313450.7670454618, - "ticks": 528, + "min": 1119292, + "max": 2534958, + "p25": 1148250, + "p50": 1172459, + "p75": 1225875, + "p99": 1909667, + "p999": 2028708, + "avg": 1228998.7442680995, + "ticks": 567, "heap": { - "_": 518, - "total": 401908224, - "min": 35368, - "max": 1996120, - "avg": 775884.6023166024 + "_": 555, + "total": 434987696, + "min": 71480, + "max": 2423864, + "avg": 783761.6144144144 } }, "args": {}, - "name": "Small File (modrrnize.js - 9.28KB)" + "name": "Small File (modrrnize.js - 9.31KB)" }, { "stats": { "kind": "fn", - "min": 1071451, - "max": 3882735, - "p25": 1169298, - "p50": 1256548, - "p75": 1410751, - "p99": 2367748, - "p999": 2879458, - "avg": 1334653.4566473989, - "ticks": 519, + "min": 1121292, + "max": 2300333, + "p25": 1141916, + "p50": 1154500, + "p75": 1184375, + "p99": 1806791, + "p999": 2001625, + "avg": 1196129.3865979381, + "ticks": 582, "heap": { - "_": 515, - "total": 394701408, - "min": 42672, - "max": 2611568, - "avg": 766410.5009708737 + "_": 572, + "total": 441818968, + "min": 43376, + "max": 2248616, + "avg": 772410.7832167832 } }, "args": {}, - "name": "Small File (smith.js - 9.28KB)" + "name": "Small File (smith.js - 9.31KB)" }, { "stats": { "kind": "fn", - "min": 2170172, - "max": 4759103, - "p25": 2250172, - "p50": 2579077, - "p75": 2685596, - "p99": 4296487, - "p999": 4705912, - "avg": 2582440.4210526315, - "ticks": 266, + "min": 2424208, + "max": 4414417, + "p25": 2464250, + "p50": 2482125, + "p75": 2543833, + "p99": 4008458, + "p999": 4261541, + "avg": 2566759.350746269, + "ticks": 268, "heap": { - "_": 263, - "total": 367423664, - "min": 4048, - "max": 2785840, - "avg": 1397048.1520912547 + "_": 267, + "total": 369707480, + "min": 68952, + "max": 2794152, + "avg": 1384672.2097378278 } }, "args": {}, - "name": "Medium File (kopiluwak.js - 15.45KB)" + "name": "Medium File (kopiluwak.js - 15.53KB)" }, { "stats": { "kind": "fn", - "min": 73442120, - "max": 79203007, - "p25": 75315575, - "p50": 75690579, - "p75": 76291331, - "p99": 78556516, - "p999": 78556516, - "avg": 76256814.6, - "ticks": 10, + "min": 78239833, + "max": 82879708, + "p25": 78685834, + "p50": 80037459, + "p75": 80591375, + "p99": 82183625, + "p999": 82183625, + "avg": 80202344.72727273, + "ticks": 11, "heap": { - "_": 14, - "total": 461557832, - "min": 26429840, - "max": 35289552, - "avg": 32968416.57142857 + "_": 15, + "total": 489719552, + "min": 27759336, + "max": 34236992, + "avg": 32647970.133333333 }, "gc": { - "total": 202504783, - "min": 13314961, - "max": 18337921, - "avg": 14464627.357142856 + "total": 122378876, + "min": 6685959, + "max": 9953333, + "avg": 8158591.733333333 } }, "args": {}, @@ -222,21 +222,21 @@ { "stats": { "kind": "fn", - "min": 208023, - "max": 1729049, - "p25": 249334, - "p50": 286030, - "p75": 384237, - "p99": 714985, - "p999": 1129077, - "avg": 330014.17719714966, - "ticks": 2105, + "min": 245500, + "max": 961000, + "p25": 266041, + "p50": 283417, + "p75": 309666, + "p99": 553125, + "p999": 834250, + "avg": 303603.38968357176, + "ticks": 2307, "heap": { - "_": 1659, - "total": 452366448, - "min": 1320, - "max": 1263872, - "avg": 272674.16998191684 + "_": 1801, + "total": 493369584, + "min": 4360, + "max": 1772632, + "avg": 273942.0233203776 } }, "args": {}, @@ -245,21 +245,21 @@ { "stats": { "kind": "fn", - "min": 39495558, - "max": 51692329, - "p25": 44062612, - "p50": 45607625, - "p75": 46064511, - "p99": 48203065, - "p999": 48203065, - "avg": 45576307.36363637, - "ticks": 11, + "min": 52799416, + "max": 86915625, + "p25": 54556875, + "p50": 55851958, + "p75": 65920916, + "p99": 68366875, + "p999": 68366875, + "avg": 60815708.333333336, + "ticks": 12, "heap": { - "_": 11, - "total": 233409312, - "min": 19239064, - "max": 33042392, - "avg": 21219028.363636363 + "_": 9, + "total": 195062368, + "min": 18618488, + "max": 32400816, + "avg": 21673596.444444444 } }, "args": {}, diff --git a/workspaces/js-x-ray/benchmark/report.md b/workspaces/js-x-ray/benchmark/report.md new file mode 100644 index 00000000..69372a0d --- /dev/null +++ b/workspaces/js-x-ray/benchmark/report.md @@ -0,0 +1,19 @@ +# Benchmark Report + +- **Timestamp:** 2026-06-15T05:54:25.799Z +- **Runtime:** node +- **CPU:** unknown (~3.06 GHz) + +| Benchmark | min | max | p25 | p50 | p75 | p99 | p999 | avg | samples | heap (avg) | gc (avg) | +| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | +| Small File (jscrush.js - 1.06KB) | 232.29 µs | 971.25 µs | 243.96 µs | 256.13 µs | 270.63 µs | 466.13 µs | 819.46 µs | 267.25 µs | 2620 | 267.10 KB | — | +| Small File (npm-audit.js - 1.51KB) | 590.13 µs | 1.60 ms | 623.58 µs | 638.04 µs | 655.79 µs | 1.02 ms | 1.20 ms | 655.34 µs | 1067 | 431.64 KB | — | +| Small File (forbes-skimmer.js - 2.20KB) | 1.48 ms | 3.29 ms | 1.51 ms | 1.53 ms | 1.57 ms | 2.70 ms | 3.04 ms | 1.59 ms | 436 | 668.69 KB | — | +| Small File (rate-map.js - 2.30KB) | 1.25 ms | 3.00 ms | 1.29 ms | 1.32 ms | 1.38 ms | 2.60 ms | 2.82 ms | 1.39 ms | 500 | 703.62 KB | — | +| Small File (event-stream.js - 3.84KB) | 1.74 ms | 5.40 ms | 1.83 ms | 1.92 ms | 2.10 ms | 3.53 ms | 5.16 ms | 2.03 ms | 338 | 890.83 KB | — | +| Small File (modrrnize.js - 9.31KB) | 1.12 ms | 2.53 ms | 1.15 ms | 1.17 ms | 1.23 ms | 1.91 ms | 2.03 ms | 1.23 ms | 567 | 765.39 KB | — | +| Small File (smith.js - 9.31KB) | 1.12 ms | 2.30 ms | 1.14 ms | 1.15 ms | 1.18 ms | 1.81 ms | 2.00 ms | 1.20 ms | 582 | 754.31 KB | — | +| Medium File (kopiluwak.js - 15.53KB) | 2.42 ms | 4.41 ms | 2.46 ms | 2.48 ms | 2.54 ms | 4.01 ms | 4.26 ms | 2.57 ms | 268 | 1.32 MB | — | +| Large File (obfuscate.js - 89.57KB) | 78.24 ms | 82.88 ms | 78.69 ms | 80.04 ms | 80.59 ms | 82.18 ms | 82.18 ms | 80.20 ms | 11 | 31.14 MB | 8.16 ms | +| jscrush.js | 245.50 µs | 961.00 µs | 266.04 µs | 283.42 µs | 309.67 µs | 553.13 µs | 834.25 µs | 303.60 µs | 2307 | 267.52 KB | — | +| obfuscate.js | 52.80 ms | 86.92 ms | 54.56 ms | 55.85 ms | 65.92 ms | 68.37 ms | 68.37 ms | 60.82 ms | 12 | 20.67 MB | — | From 6d5476511c9ab9e35dcaff12f34fd54eaa206bd7 Mon Sep 17 00:00:00 2001 From: Resham Pokhrel Date: Mon, 15 Jun 2026 01:08:03 -0500 Subject: [PATCH 03/11] fixes linter issue --- .../js-x-ray/benchmark/write-snapshot.ts | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/workspaces/js-x-ray/benchmark/write-snapshot.ts b/workspaces/js-x-ray/benchmark/write-snapshot.ts index 7a430e47..555c0aab 100644 --- a/workspaces/js-x-ray/benchmark/write-snapshot.ts +++ b/workspaces/js-x-ray/benchmark/write-snapshot.ts @@ -9,6 +9,10 @@ const kReportMarkdownURL = new URL("report.md", import.meta.url); const results = await benchmark(); +const KB = 1_024; +const MB = 1_024 ** 2; +const GB = 1_024 ** 3; + const relevantResults = { timestamp: new Date().toISOString(), runtime: results.context.runtime, @@ -34,7 +38,7 @@ const relevantResults = { writeFileSync(kReportURL, JSON.stringify(relevantResults, null, 2)); // Human-readable snapshot as a Markdown table. -writeFileSync(kReportMarkdownURL, toMarkdown(relevantResults)) +writeFileSync(kReportMarkdownURL, toMarkdown(relevantResults)); /** * mitata reports timings in nanoseconds. Picks the most readable unit. @@ -57,17 +61,17 @@ function formatDuration(nanoseconds: number): string { * heap stats are reported in bytes. */ function formatBytes(bytes: number): string { - if (bytes < 1_024) { + if (bytes < KB) { return `${bytes.toFixed(0)} B`; } - if (bytes < 1_024 ** 2) { - return `${(bytes / 1_024).toFixed(2)} KB`; + if (bytes < MB) { + return `${(bytes / KB).toFixed(2)} KB`; } - if (bytes < 1_024 ** 3) { - return `${(bytes / 1_024 ** 2).toFixed(2)} MB`; + if (bytes < GB) { + return `${(bytes / MB).toFixed(2)} MB`; } - return `${(bytes / 1_024 ** 3).toFixed(2)} GB`; + return `${(bytes / GB).toFixed(2)} GB`; } function toMarkdown(report: typeof relevantResults): string { @@ -106,4 +110,4 @@ function toMarkdown(report: typeof relevantResults): string { } return lines.join("\n") + "\n"; -} \ No newline at end of file +} From 03df08446946570c56f61f14a173022eba3c7cb5 Mon Sep 17 00:00:00 2001 From: Resham Pokhrel Date: Mon, 15 Jun 2026 01:08:29 -0500 Subject: [PATCH 04/11] re-ran benchmark report --- workspaces/js-x-ray/benchmark/report.json | 312 +++++++++++----------- workspaces/js-x-ray/benchmark/report.md | 26 +- 2 files changed, 169 insertions(+), 169 deletions(-) diff --git a/workspaces/js-x-ray/benchmark/report.json b/workspaces/js-x-ray/benchmark/report.json index de67bc66..2847f2c2 100644 --- a/workspaces/js-x-ray/benchmark/report.json +++ b/workspaces/js-x-ray/benchmark/report.json @@ -1,29 +1,29 @@ { - "timestamp": "2026-06-15T05:54:25.799Z", + "timestamp": "2026-06-15T06:06:23.368Z", "runtime": "node", "cpu": { "name": "unknown", - "freq": 3.0572688134078336 + "freq": 3.068704603276939 }, "benchmarks": [ { "stats": { "kind": "fn", - "min": 232292, - "max": 971250, - "p25": 243959, - "p50": 256125, - "p75": 270625, - "p99": 466125, - "p999": 819459, - "avg": 267252.82290076336, - "ticks": 2620, + "min": 235291, + "max": 892542.0000004768, + "p25": 246791, + "p50": 258208, + "p75": 272000, + "p99": 439333.00000047684, + "p999": 783292, + "avg": 268005.1859219607, + "ticks": 2614, "heap": { - "_": 2037, - "total": 557137848, - "min": 1944, - "max": 2619656, - "avg": 273509.0073637703 + "_": 2031, + "total": 557615600, + "min": 2496, + "max": 2533056, + "avg": 274552.24027572625 } }, "args": {}, @@ -32,21 +32,21 @@ { "stats": { "kind": "fn", - "min": 590125, - "max": 1603791, - "p25": 623584, - "p50": 638042, - "p75": 655792, - "p99": 1021958, - "p999": 1200959, - "avg": 655344.6476101219, - "ticks": 1067, + "min": 590708, + "max": 1557916, + "p25": 623333, + "p50": 637042, + "p75": 659084, + "p99": 996000, + "p999": 1170708, + "avg": 657261.4605263158, + "ticks": 1064, "heap": { - "_": 937, - "total": 414151968, - "min": 336, - "max": 3387600, - "avg": 441997.83137673425 + "_": 949, + "total": 410874016, + "min": 56, + "max": 3093600, + "avg": 432954.70600632246 } }, "args": {}, @@ -55,21 +55,21 @@ { "stats": { "kind": "fn", - "min": 1482750, - "max": 3286333, - "p25": 1510708, - "p50": 1530750, - "p75": 1574541, - "p99": 2704542, - "p999": 3038750, - "avg": 1593130.360091743, - "ticks": 436, + "min": 1503584, + "max": 3273292, + "p25": 1542958, + "p50": 1575625, + "p75": 1651125, + "p99": 2759917, + "p999": 3074459, + "avg": 1646354.8028503563, + "ticks": 421, "heap": { - "_": 428, - "total": 293069656, - "min": 21064, - "max": 1965032, - "avg": 684742.1869158879 + "_": 415, + "total": 282736608, + "min": 20944, + "max": 1919024, + "avg": 681293.0313253012 } }, "args": {}, @@ -78,21 +78,21 @@ { "stats": { "kind": "fn", - "min": 1251708, - "max": 2998084, - "p25": 1289750, - "p50": 1323833, - "p75": 1378292, - "p99": 2599834, - "p999": 2821292, - "avg": 1386856.832, - "ticks": 500, + "min": 1240917, + "max": 3094042, + "p25": 1270833, + "p50": 1303167, + "p75": 1375417, + "p99": 2492125, + "p999": 2823084, + "avg": 1372375.1837944663, + "ticks": 506, "heap": { - "_": 487, - "total": 350886992, - "min": 9672, - "max": 2624600, - "avg": 720507.1704312115 + "_": 497, + "total": 346467336, + "min": 23472, + "max": 2388584, + "avg": 697117.3762575453 } }, "args": {}, @@ -101,21 +101,21 @@ { "stats": { "kind": "fn", - "min": 1743584, - "max": 5401708, - "p25": 1827209, - "p50": 1918917, - "p75": 2095458, - "p99": 3525042, - "p999": 5155291, - "avg": 2029107.8609467456, - "ticks": 338, + "min": 1734875, + "max": 3176750, + "p25": 1785916, + "p50": 1814208, + "p75": 1871500, + "p99": 2667167, + "p999": 2960208, + "avg": 1868185.2189189189, + "ticks": 370, "heap": { - "_": 333, - "total": 303764776, - "min": 11432, - "max": 3204304, - "avg": 912206.5345345346 + "_": 366, + "total": 340439960, + "min": 207008, + "max": 2730912, + "avg": 930163.825136612 } }, "args": {}, @@ -124,21 +124,21 @@ { "stats": { "kind": "fn", - "min": 1119292, - "max": 2534958, - "p25": 1148250, - "p50": 1172459, - "p75": 1225875, - "p99": 1909667, - "p999": 2028708, - "avg": 1228998.7442680995, - "ticks": 567, + "min": 1098417.0000009537, + "max": 2409541, + "p25": 1119542, + "p50": 1139500, + "p75": 1176750, + "p99": 1795375, + "p999": 1965083, + "avg": 1180347.1050847296, + "ticks": 590, "heap": { - "_": 555, - "total": 434987696, - "min": 71480, - "max": 2423864, - "avg": 783761.6144144144 + "_": 580, + "total": 452870624, + "min": 55784, + "max": 2346608, + "avg": 780811.4206896551 } }, "args": {}, @@ -147,21 +147,21 @@ { "stats": { "kind": "fn", - "min": 1121292, - "max": 2300333, - "p25": 1141916, - "p50": 1154500, - "p75": 1184375, - "p99": 1806791, - "p999": 2001625, - "avg": 1196129.3865979381, - "ticks": 582, + "min": 1091500, + "max": 2274667.0000019073, + "p25": 1114458, + "p50": 1131125, + "p75": 1158250, + "p99": 1686583.9999990463, + "p999": 1983959, + "avg": 1165778.0770519327, + "ticks": 597, "heap": { - "_": 572, - "total": 441818968, - "min": 43376, - "max": 2248616, - "avg": 772410.7832167832 + "_": 587, + "total": 455354744, + "min": 46392, + "max": 2128312, + "avg": 775732.1022146507 } }, "args": {}, @@ -170,21 +170,21 @@ { "stats": { "kind": "fn", - "min": 2424208, - "max": 4414417, - "p25": 2464250, - "p50": 2482125, - "p75": 2543833, - "p99": 4008458, - "p999": 4261541, - "avg": 2566759.350746269, - "ticks": 268, + "min": 2469417, + "max": 4896583, + "p25": 2498334, + "p50": 2520042, + "p75": 2609334, + "p99": 4453250, + "p999": 4728417, + "avg": 2635028.421455939, + "ticks": 261, "heap": { - "_": 267, - "total": 369707480, - "min": 68952, - "max": 2794152, - "avg": 1384672.2097378278 + "_": 260, + "total": 362054384, + "min": 4256, + "max": 2722592, + "avg": 1392516.8615384616 } }, "args": {}, @@ -193,27 +193,27 @@ { "stats": { "kind": "fn", - "min": 78239833, - "max": 82879708, - "p25": 78685834, - "p50": 80037459, - "p75": 80591375, - "p99": 82183625, - "p999": 82183625, - "avg": 80202344.72727273, + "min": 76393000, + "max": 81881209, + "p25": 77871251, + "p50": 79026709, + "p75": 79429667, + "p99": 81306125, + "p999": 81306125, + "avg": 79173223.72727273, "ticks": 11, "heap": { "_": 15, - "total": 489719552, - "min": 27759336, - "max": 34236992, - "avg": 32647970.133333333 + "total": 492398216, + "min": 27879272, + "max": 35268048, + "avg": 32826547.733333334 }, "gc": { - "total": 122378876, - "min": 6685959, - "max": 9953333, - "avg": 8158591.733333333 + "total": 112758832, + "min": 6621875, + "max": 8767917, + "avg": 7517255.466666667 } }, "args": {}, @@ -223,20 +223,20 @@ "stats": { "kind": "fn", "min": 245500, - "max": 961000, - "p25": 266041, - "p50": 283417, - "p75": 309666, - "p99": 553125, - "p999": 834250, - "avg": 303603.38968357176, - "ticks": 2307, + "max": 935542, + "p25": 260875, + "p50": 273417, + "p75": 288917, + "p99": 541625, + "p999": 871625, + "avg": 286457.6819296811, + "ticks": 2446, "heap": { - "_": 1801, - "total": 493369584, - "min": 4360, - "max": 1772632, - "avg": 273942.0233203776 + "_": 1883, + "total": 519389552, + "min": 17696, + "max": 1184600, + "avg": 275830.8826340945 } }, "args": {}, @@ -245,21 +245,21 @@ { "stats": { "kind": "fn", - "min": 52799416, - "max": 86915625, - "p25": 54556875, - "p50": 55851958, - "p75": 65920916, - "p99": 68366875, - "p999": 68366875, - "avg": 60815708.333333336, - "ticks": 12, + "min": 52316041, + "max": 58197750, + "p25": 53394084, + "p50": 53916291, + "p75": 54564084, + "p99": 55393041, + "p999": 55393041, + "avg": 54313592.55555555, + "ticks": 9, "heap": { "_": 9, - "total": 195062368, - "min": 18618488, - "max": 32400816, - "avg": 21673596.444444444 + "total": 195786072, + "min": 18707296, + "max": 30810336, + "avg": 21754008 } }, "args": {}, diff --git a/workspaces/js-x-ray/benchmark/report.md b/workspaces/js-x-ray/benchmark/report.md index 69372a0d..edaca060 100644 --- a/workspaces/js-x-ray/benchmark/report.md +++ b/workspaces/js-x-ray/benchmark/report.md @@ -1,19 +1,19 @@ # Benchmark Report -- **Timestamp:** 2026-06-15T05:54:25.799Z +- **Timestamp:** 2026-06-15T06:06:23.368Z - **Runtime:** node -- **CPU:** unknown (~3.06 GHz) +- **CPU:** unknown (~3.07 GHz) | Benchmark | min | max | p25 | p50 | p75 | p99 | p999 | avg | samples | heap (avg) | gc (avg) | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | -| Small File (jscrush.js - 1.06KB) | 232.29 µs | 971.25 µs | 243.96 µs | 256.13 µs | 270.63 µs | 466.13 µs | 819.46 µs | 267.25 µs | 2620 | 267.10 KB | — | -| Small File (npm-audit.js - 1.51KB) | 590.13 µs | 1.60 ms | 623.58 µs | 638.04 µs | 655.79 µs | 1.02 ms | 1.20 ms | 655.34 µs | 1067 | 431.64 KB | — | -| Small File (forbes-skimmer.js - 2.20KB) | 1.48 ms | 3.29 ms | 1.51 ms | 1.53 ms | 1.57 ms | 2.70 ms | 3.04 ms | 1.59 ms | 436 | 668.69 KB | — | -| Small File (rate-map.js - 2.30KB) | 1.25 ms | 3.00 ms | 1.29 ms | 1.32 ms | 1.38 ms | 2.60 ms | 2.82 ms | 1.39 ms | 500 | 703.62 KB | — | -| Small File (event-stream.js - 3.84KB) | 1.74 ms | 5.40 ms | 1.83 ms | 1.92 ms | 2.10 ms | 3.53 ms | 5.16 ms | 2.03 ms | 338 | 890.83 KB | — | -| Small File (modrrnize.js - 9.31KB) | 1.12 ms | 2.53 ms | 1.15 ms | 1.17 ms | 1.23 ms | 1.91 ms | 2.03 ms | 1.23 ms | 567 | 765.39 KB | — | -| Small File (smith.js - 9.31KB) | 1.12 ms | 2.30 ms | 1.14 ms | 1.15 ms | 1.18 ms | 1.81 ms | 2.00 ms | 1.20 ms | 582 | 754.31 KB | — | -| Medium File (kopiluwak.js - 15.53KB) | 2.42 ms | 4.41 ms | 2.46 ms | 2.48 ms | 2.54 ms | 4.01 ms | 4.26 ms | 2.57 ms | 268 | 1.32 MB | — | -| Large File (obfuscate.js - 89.57KB) | 78.24 ms | 82.88 ms | 78.69 ms | 80.04 ms | 80.59 ms | 82.18 ms | 82.18 ms | 80.20 ms | 11 | 31.14 MB | 8.16 ms | -| jscrush.js | 245.50 µs | 961.00 µs | 266.04 µs | 283.42 µs | 309.67 µs | 553.13 µs | 834.25 µs | 303.60 µs | 2307 | 267.52 KB | — | -| obfuscate.js | 52.80 ms | 86.92 ms | 54.56 ms | 55.85 ms | 65.92 ms | 68.37 ms | 68.37 ms | 60.82 ms | 12 | 20.67 MB | — | +| Small File (jscrush.js - 1.06KB) | 235.29 µs | 892.54 µs | 246.79 µs | 258.21 µs | 272.00 µs | 439.33 µs | 783.29 µs | 268.01 µs | 2614 | 268.12 KB | — | +| Small File (npm-audit.js - 1.51KB) | 590.71 µs | 1.56 ms | 623.33 µs | 637.04 µs | 659.08 µs | 996.00 µs | 1.17 ms | 657.26 µs | 1064 | 422.81 KB | — | +| Small File (forbes-skimmer.js - 2.20KB) | 1.50 ms | 3.27 ms | 1.54 ms | 1.58 ms | 1.65 ms | 2.76 ms | 3.07 ms | 1.65 ms | 421 | 665.33 KB | — | +| Small File (rate-map.js - 2.30KB) | 1.24 ms | 3.09 ms | 1.27 ms | 1.30 ms | 1.38 ms | 2.49 ms | 2.82 ms | 1.37 ms | 506 | 680.78 KB | — | +| Small File (event-stream.js - 3.84KB) | 1.73 ms | 3.18 ms | 1.79 ms | 1.81 ms | 1.87 ms | 2.67 ms | 2.96 ms | 1.87 ms | 370 | 908.36 KB | — | +| Small File (modrrnize.js - 9.31KB) | 1.10 ms | 2.41 ms | 1.12 ms | 1.14 ms | 1.18 ms | 1.80 ms | 1.97 ms | 1.18 ms | 590 | 762.51 KB | — | +| Small File (smith.js - 9.31KB) | 1.09 ms | 2.27 ms | 1.11 ms | 1.13 ms | 1.16 ms | 1.69 ms | 1.98 ms | 1.17 ms | 597 | 757.55 KB | — | +| Medium File (kopiluwak.js - 15.53KB) | 2.47 ms | 4.90 ms | 2.50 ms | 2.52 ms | 2.61 ms | 4.45 ms | 4.73 ms | 2.64 ms | 261 | 1.33 MB | — | +| Large File (obfuscate.js - 89.57KB) | 76.39 ms | 81.88 ms | 77.87 ms | 79.03 ms | 79.43 ms | 81.31 ms | 81.31 ms | 79.17 ms | 11 | 31.31 MB | 7.52 ms | +| jscrush.js | 245.50 µs | 935.54 µs | 260.88 µs | 273.42 µs | 288.92 µs | 541.63 µs | 871.63 µs | 286.46 µs | 2446 | 269.37 KB | — | +| obfuscate.js | 52.32 ms | 58.20 ms | 53.39 ms | 53.92 ms | 54.56 ms | 55.39 ms | 55.39 ms | 54.31 ms | 9 | 20.75 MB | — | From f7d69e9c8f570541d33e48effafd44fcb0fdcea3 Mon Sep 17 00:00:00 2001 From: Resham Pokhrel Date: Sun, 21 Jun 2026 21:27:34 -0500 Subject: [PATCH 05/11] refactor(reports): move markdown generation to separate ts file --- workspaces/js-x-ray/benchmark/markdown.ts | 97 ++++++ workspaces/js-x-ray/benchmark/report.json | 312 +++++++++--------- workspaces/js-x-ray/benchmark/report.md | 26 +- .../js-x-ray/benchmark/write-snapshot.ts | 77 +---- 4 files changed, 267 insertions(+), 245 deletions(-) create mode 100644 workspaces/js-x-ray/benchmark/markdown.ts diff --git a/workspaces/js-x-ray/benchmark/markdown.ts b/workspaces/js-x-ray/benchmark/markdown.ts new file mode 100644 index 00000000..e8307bdc --- /dev/null +++ b/workspaces/js-x-ray/benchmark/markdown.ts @@ -0,0 +1,97 @@ +const KB = 1_024; +const MB = 1_024 ** 2; +const GB = 1_024 ** 3; + +export interface BenchmarkReport { + timestamp: string; + runtime: string; + cpu: { name: string; freq: number; }; + benchmarks: Array<{ + name: string; + stats: { + min: number; + max: number; + p25: number; + p50: number; + p75: number; + p99: number; + p999: number; + avg: number; + ticks: number; + heap?: { avg: number; }; + gc?: { avg: number; }; + }; + }>; +} + +/** + * mitata reports timings in nanoseconds. Picks the most readable unit. + */ +export function formatDuration(nanoseconds: number): string { + if (nanoseconds < 1_000) { + return `${nanoseconds.toFixed(2)} ns`; + } + if (nanoseconds < 1_000_000) { + return `${(nanoseconds / 1_000).toFixed(2)} µs`; + } + if (nanoseconds < 1_000_000_000) { + return `${(nanoseconds / 1_000_000).toFixed(2)} ms`; + } + + return `${(nanoseconds / 1_000_000_000).toFixed(2)} s`; +} + +/** + * heap stats are reported in bytes. + */ +export function formatBytes(bytes: number): string { + if (bytes < KB) { + return `${bytes.toFixed(0)} B`; + } + if (bytes < MB) { + return `${(bytes / KB).toFixed(2)} KB`; + } + if (bytes < GB) { + return `${(bytes / MB).toFixed(2)} MB`; + } + + return `${(bytes / GB).toFixed(2)} GB`; +} + +export function toMarkdown(report: BenchmarkReport): string { + const header = [ + "Benchmark", "min", "max", "p25", "p50", "p75", "p99", "p999", "avg", "samples", "heap (avg)", "gc (avg)" + ]; + + const lines = [ + "# Benchmark Report", + "", + `- **Timestamp:** ${report.timestamp}`, + `- **Runtime:** ${report.runtime}`, + `- **CPU:** ${report.cpu.name} (~${report.cpu.freq.toFixed(2)} GHz)`, + "", + `| ${header.join(" | ")} |`, + `| ${header.map(() => "---").join(" | ")} |` + ]; + + for (const { name, stats } of report.benchmarks) { + const row = [ + name, + formatDuration(stats.min), + formatDuration(stats.max), + formatDuration(stats.p25), + formatDuration(stats.p50), + formatDuration(stats.p75), + formatDuration(stats.p99), + formatDuration(stats.p999), + formatDuration(stats.avg), + String(stats.ticks), + stats.heap ? formatBytes(stats.heap.avg) : "—", + stats.gc ? formatDuration(stats.gc.avg) : "—" + ]; + + lines.push(`| ${row.join(" | ")} |`); + } + + return lines.join("\n") + "\n"; +} diff --git a/workspaces/js-x-ray/benchmark/report.json b/workspaces/js-x-ray/benchmark/report.json index 2847f2c2..15351cdc 100644 --- a/workspaces/js-x-ray/benchmark/report.json +++ b/workspaces/js-x-ray/benchmark/report.json @@ -1,29 +1,29 @@ { - "timestamp": "2026-06-15T06:06:23.368Z", + "timestamp": "2026-06-22T02:23:51.314Z", "runtime": "node", "cpu": { "name": "unknown", - "freq": 3.068704603276939 + "freq": 3.0750483158698763 }, "benchmarks": [ { "stats": { "kind": "fn", - "min": 235291, - "max": 892542.0000004768, - "p25": 246791, - "p50": 258208, - "p75": 272000, - "p99": 439333.00000047684, - "p999": 783292, - "avg": 268005.1859219607, - "ticks": 2614, + "min": 233750, + "max": 982459, + "p25": 245750, + "p50": 256542, + "p75": 270917, + "p99": 452833, + "p999": 783041, + "avg": 266753.44935262756, + "ticks": 2626, "heap": { - "_": 2031, - "total": 557615600, - "min": 2496, - "max": 2533056, - "avg": 274552.24027572625 + "_": 2046, + "total": 559628528, + "min": 2256, + "max": 2758736, + "avg": 273523.22971652006 } }, "args": {}, @@ -32,21 +32,21 @@ { "stats": { "kind": "fn", - "min": 590708, - "max": 1557916, - "p25": 623333, - "p50": 637042, - "p75": 659084, - "p99": 996000, - "p999": 1170708, - "avg": 657261.4605263158, - "ticks": 1064, + "min": 596291, + "max": 1789375, + "p25": 627125, + "p50": 641834, + "p75": 661708, + "p99": 1025291, + "p999": 1207750, + "avg": 660613.7892249527, + "ticks": 1058, "heap": { - "_": 949, - "total": 410874016, - "min": 56, - "max": 3093600, - "avg": 432954.70600632246 + "_": 935, + "total": 407804752, + "min": 1536, + "max": 3052640, + "avg": 436154.814973262 } }, "args": {}, @@ -55,21 +55,21 @@ { "stats": { "kind": "fn", - "min": 1503584, - "max": 3273292, - "p25": 1542958, - "p50": 1575625, - "p75": 1651125, - "p99": 2759917, - "p999": 3074459, - "avg": 1646354.8028503563, - "ticks": 421, + "min": 1486416, + "max": 3350500, + "p25": 1507958, + "p50": 1530875, + "p75": 1588917, + "p99": 2835541, + "p999": 3311625, + "avg": 1595889.388505747, + "ticks": 435, "heap": { - "_": 415, - "total": 282736608, - "min": 20944, - "max": 1919024, - "avg": 681293.0313253012 + "_": 428, + "total": 292233552, + "min": 36232, + "max": 1995208, + "avg": 682788.6728971963 } }, "args": {}, @@ -78,21 +78,21 @@ { "stats": { "kind": "fn", - "min": 1240917, - "max": 3094042, - "p25": 1270833, - "p50": 1303167, - "p75": 1375417, - "p99": 2492125, - "p999": 2823084, - "avg": 1372375.1837944663, - "ticks": 506, + "min": 1233541, + "max": 2995792, + "p25": 1262875, + "p50": 1289459, + "p75": 1329250, + "p99": 2573000, + "p999": 2799584, + "avg": 1348236.1805825243, + "ticks": 515, "heap": { - "_": 497, - "total": 346467336, - "min": 23472, - "max": 2388584, - "avg": 697117.3762575453 + "_": 500, + "total": 357976488, + "min": 66512, + "max": 2587224, + "avg": 715952.976 } }, "args": {}, @@ -101,21 +101,21 @@ { "stats": { "kind": "fn", - "min": 1734875, - "max": 3176750, - "p25": 1785916, - "p50": 1814208, - "p75": 1871500, - "p99": 2667167, - "p999": 2960208, - "avg": 1868185.2189189189, - "ticks": 370, + "min": 1713500, + "max": 2967792, + "p25": 1755000, + "p50": 1776750, + "p75": 1824417, + "p99": 2658000, + "p999": 2823875, + "avg": 1827884.2295514513, + "ticks": 379, "heap": { - "_": 366, - "total": 340439960, - "min": 207008, - "max": 2730912, - "avg": 930163.825136612 + "_": 377, + "total": 336534728, + "min": 82240, + "max": 2313544, + "avg": 892665.0610079576 } }, "args": {}, @@ -124,21 +124,21 @@ { "stats": { "kind": "fn", - "min": 1098417.0000009537, - "max": 2409541, - "p25": 1119542, - "p50": 1139500, - "p75": 1176750, - "p99": 1795375, - "p999": 1965083, - "avg": 1180347.1050847296, - "ticks": 590, + "min": 1056250, + "max": 3197333, + "p25": 1091999.9999990463, + "p50": 1116292, + "p75": 1164375, + "p99": 1912250, + "p999": 2935625.0000009537, + "avg": 1168175.332214786, + "ticks": 596, "heap": { - "_": 580, - "total": 452870624, - "min": 55784, - "max": 2346608, - "avg": 780811.4206896551 + "_": 582, + "total": 453112688, + "min": 95256, + "max": 2084296, + "avg": 778544.1374570447 } }, "args": {}, @@ -147,21 +147,21 @@ { "stats": { "kind": "fn", - "min": 1091500, - "max": 2274667.0000019073, - "p25": 1114458, - "p50": 1131125, - "p75": 1158250, - "p99": 1686583.9999990463, - "p999": 1983959, - "avg": 1165778.0770519327, - "ticks": 597, + "min": 1063666, + "max": 2262292, + "p25": 1083666, + "p50": 1099792, + "p75": 1130375, + "p99": 1721333, + "p999": 1978084, + "avg": 1137614.290849673, + "ticks": 612, "heap": { - "_": 587, - "total": 455354744, - "min": 46392, - "max": 2128312, - "avg": 775732.1022146507 + "_": 601, + "total": 459221464, + "min": 145376, + "max": 2236544, + "avg": 764095.6139767055 } }, "args": {}, @@ -170,21 +170,21 @@ { "stats": { "kind": "fn", - "min": 2469417, - "max": 4896583, - "p25": 2498334, - "p50": 2520042, - "p75": 2609334, - "p99": 4453250, - "p999": 4728417, - "avg": 2635028.421455939, - "ticks": 261, + "min": 2352459, + "max": 4936250, + "p25": 2387167, + "p50": 2403292, + "p75": 2465291, + "p99": 4659208, + "p999": 4828500, + "avg": 2504388.6145454547, + "ticks": 275, "heap": { - "_": 260, - "total": 362054384, - "min": 4256, - "max": 2722592, - "avg": 1392516.8615384616 + "_": 273, + "total": 382511704, + "min": 2344, + "max": 3340776, + "avg": 1401141.772893773 } }, "args": {}, @@ -193,27 +193,27 @@ { "stats": { "kind": "fn", - "min": 76393000, - "max": 81881209, - "p25": 77871251, - "p50": 79026709, - "p75": 79429667, - "p99": 81306125, - "p999": 81306125, - "avg": 79173223.72727273, + "min": 76615541, + "max": 81810917, + "p25": 78609833, + "p50": 79120000, + "p75": 79922875, + "p99": 81716542, + "p999": 81716542, + "avg": 79406102.27272727, "ticks": 11, "heap": { "_": 15, - "total": 492398216, - "min": 27879272, - "max": 35268048, - "avg": 32826547.733333334 + "total": 492130520, + "min": 27769928, + "max": 34951936, + "avg": 32808701.333333332 }, "gc": { - "total": 112758832, - "min": 6621875, - "max": 8767917, - "avg": 7517255.466666667 + "total": 120333333, + "min": 6681541, + "max": 12206583, + "avg": 8022222.2 } }, "args": {}, @@ -222,21 +222,21 @@ { "stats": { "kind": "fn", - "min": 245500, - "max": 935542, - "p25": 260875, - "p50": 273417, - "p75": 288917, - "p99": 541625, - "p999": 871625, - "avg": 286457.6819296811, - "ticks": 2446, + "min": 245083, + "max": 961792, + "p25": 263333, + "p50": 276666, + "p75": 296292, + "p99": 515917, + "p999": 886625, + "avg": 291390.227953411, + "ticks": 2404, "heap": { - "_": 1883, - "total": 519389552, - "min": 17696, - "max": 1184600, - "avg": 275830.8826340945 + "_": 1865, + "total": 506157440, + "min": 1728, + "max": 1605112, + "avg": 271398.09115281503 } }, "args": {}, @@ -245,21 +245,21 @@ { "stats": { "kind": "fn", - "min": 52316041, - "max": 58197750, - "p25": 53394084, - "p50": 53916291, - "p75": 54564084, - "p99": 55393041, - "p999": 55393041, - "avg": 54313592.55555555, + "min": 52208417, + "max": 58259916, + "p25": 53704167, + "p50": 54129458, + "p75": 54798500, + "p99": 56464833, + "p999": 56464833, + "avg": 54452370.222222224, "ticks": 9, "heap": { "_": 9, - "total": 195786072, - "min": 18707296, - "max": 30810336, - "avg": 21754008 + "total": 193557832, + "min": 18627040, + "max": 30725312, + "avg": 21506425.777777776 } }, "args": {}, diff --git a/workspaces/js-x-ray/benchmark/report.md b/workspaces/js-x-ray/benchmark/report.md index edaca060..c466d65f 100644 --- a/workspaces/js-x-ray/benchmark/report.md +++ b/workspaces/js-x-ray/benchmark/report.md @@ -1,19 +1,19 @@ # Benchmark Report -- **Timestamp:** 2026-06-15T06:06:23.368Z +- **Timestamp:** 2026-06-22T02:23:51.314Z - **Runtime:** node -- **CPU:** unknown (~3.07 GHz) +- **CPU:** unknown (~3.08 GHz) | Benchmark | min | max | p25 | p50 | p75 | p99 | p999 | avg | samples | heap (avg) | gc (avg) | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | -| Small File (jscrush.js - 1.06KB) | 235.29 µs | 892.54 µs | 246.79 µs | 258.21 µs | 272.00 µs | 439.33 µs | 783.29 µs | 268.01 µs | 2614 | 268.12 KB | — | -| Small File (npm-audit.js - 1.51KB) | 590.71 µs | 1.56 ms | 623.33 µs | 637.04 µs | 659.08 µs | 996.00 µs | 1.17 ms | 657.26 µs | 1064 | 422.81 KB | — | -| Small File (forbes-skimmer.js - 2.20KB) | 1.50 ms | 3.27 ms | 1.54 ms | 1.58 ms | 1.65 ms | 2.76 ms | 3.07 ms | 1.65 ms | 421 | 665.33 KB | — | -| Small File (rate-map.js - 2.30KB) | 1.24 ms | 3.09 ms | 1.27 ms | 1.30 ms | 1.38 ms | 2.49 ms | 2.82 ms | 1.37 ms | 506 | 680.78 KB | — | -| Small File (event-stream.js - 3.84KB) | 1.73 ms | 3.18 ms | 1.79 ms | 1.81 ms | 1.87 ms | 2.67 ms | 2.96 ms | 1.87 ms | 370 | 908.36 KB | — | -| Small File (modrrnize.js - 9.31KB) | 1.10 ms | 2.41 ms | 1.12 ms | 1.14 ms | 1.18 ms | 1.80 ms | 1.97 ms | 1.18 ms | 590 | 762.51 KB | — | -| Small File (smith.js - 9.31KB) | 1.09 ms | 2.27 ms | 1.11 ms | 1.13 ms | 1.16 ms | 1.69 ms | 1.98 ms | 1.17 ms | 597 | 757.55 KB | — | -| Medium File (kopiluwak.js - 15.53KB) | 2.47 ms | 4.90 ms | 2.50 ms | 2.52 ms | 2.61 ms | 4.45 ms | 4.73 ms | 2.64 ms | 261 | 1.33 MB | — | -| Large File (obfuscate.js - 89.57KB) | 76.39 ms | 81.88 ms | 77.87 ms | 79.03 ms | 79.43 ms | 81.31 ms | 81.31 ms | 79.17 ms | 11 | 31.31 MB | 7.52 ms | -| jscrush.js | 245.50 µs | 935.54 µs | 260.88 µs | 273.42 µs | 288.92 µs | 541.63 µs | 871.63 µs | 286.46 µs | 2446 | 269.37 KB | — | -| obfuscate.js | 52.32 ms | 58.20 ms | 53.39 ms | 53.92 ms | 54.56 ms | 55.39 ms | 55.39 ms | 54.31 ms | 9 | 20.75 MB | — | +| Small File (jscrush.js - 1.06KB) | 233.75 µs | 982.46 µs | 245.75 µs | 256.54 µs | 270.92 µs | 452.83 µs | 783.04 µs | 266.75 µs | 2626 | 267.11 KB | — | +| Small File (npm-audit.js - 1.51KB) | 596.29 µs | 1.79 ms | 627.13 µs | 641.83 µs | 661.71 µs | 1.03 ms | 1.21 ms | 660.61 µs | 1058 | 425.93 KB | — | +| Small File (forbes-skimmer.js - 2.20KB) | 1.49 ms | 3.35 ms | 1.51 ms | 1.53 ms | 1.59 ms | 2.84 ms | 3.31 ms | 1.60 ms | 435 | 666.79 KB | — | +| Small File (rate-map.js - 2.30KB) | 1.23 ms | 3.00 ms | 1.26 ms | 1.29 ms | 1.33 ms | 2.57 ms | 2.80 ms | 1.35 ms | 515 | 699.17 KB | — | +| Small File (event-stream.js - 3.84KB) | 1.71 ms | 2.97 ms | 1.75 ms | 1.78 ms | 1.82 ms | 2.66 ms | 2.82 ms | 1.83 ms | 379 | 871.74 KB | — | +| Small File (modrrnize.js - 9.31KB) | 1.06 ms | 3.20 ms | 1.09 ms | 1.12 ms | 1.16 ms | 1.91 ms | 2.94 ms | 1.17 ms | 596 | 760.30 KB | — | +| Small File (smith.js - 9.31KB) | 1.06 ms | 2.26 ms | 1.08 ms | 1.10 ms | 1.13 ms | 1.72 ms | 1.98 ms | 1.14 ms | 612 | 746.19 KB | — | +| Medium File (kopiluwak.js - 15.53KB) | 2.35 ms | 4.94 ms | 2.39 ms | 2.40 ms | 2.47 ms | 4.66 ms | 4.83 ms | 2.50 ms | 275 | 1.34 MB | — | +| Large File (obfuscate.js - 89.57KB) | 76.62 ms | 81.81 ms | 78.61 ms | 79.12 ms | 79.92 ms | 81.72 ms | 81.72 ms | 79.41 ms | 11 | 31.29 MB | 8.02 ms | +| jscrush.js | 245.08 µs | 961.79 µs | 263.33 µs | 276.67 µs | 296.29 µs | 515.92 µs | 886.63 µs | 291.39 µs | 2404 | 265.04 KB | — | +| obfuscate.js | 52.21 ms | 58.26 ms | 53.70 ms | 54.13 ms | 54.80 ms | 56.46 ms | 56.46 ms | 54.45 ms | 9 | 20.51 MB | — | diff --git a/workspaces/js-x-ray/benchmark/write-snapshot.ts b/workspaces/js-x-ray/benchmark/write-snapshot.ts index 555c0aab..2eeb5380 100644 --- a/workspaces/js-x-ray/benchmark/write-snapshot.ts +++ b/workspaces/js-x-ray/benchmark/write-snapshot.ts @@ -3,16 +3,13 @@ import { writeFileSync } from "node:fs"; // Import Internal Dependencies import { benchmark } from "./bench.ts"; +import { toMarkdown } from "./markdown.ts"; const kReportURL = new URL("report.json", import.meta.url); const kReportMarkdownURL = new URL("report.md", import.meta.url); const results = await benchmark(); -const KB = 1_024; -const MB = 1_024 ** 2; -const GB = 1_024 ** 3; - const relevantResults = { timestamp: new Date().toISOString(), runtime: results.context.runtime, @@ -39,75 +36,3 @@ writeFileSync(kReportURL, JSON.stringify(relevantResults, null, 2)); // Human-readable snapshot as a Markdown table. writeFileSync(kReportMarkdownURL, toMarkdown(relevantResults)); - -/** - * mitata reports timings in nanoseconds. Picks the most readable unit. - */ -function formatDuration(nanoseconds: number): string { - if (nanoseconds < 1_000) { - return `${nanoseconds.toFixed(2)} ns`; - } - if (nanoseconds < 1_000_000) { - return `${(nanoseconds / 1_000).toFixed(2)} µs`; - } - if (nanoseconds < 1_000_000_000) { - return `${(nanoseconds / 1_000_000).toFixed(2)} ms`; - } - - return `${(nanoseconds / 1_000_000_000).toFixed(2)} s`; -} - -/** - * heap stats are reported in bytes. - */ -function formatBytes(bytes: number): string { - if (bytes < KB) { - return `${bytes.toFixed(0)} B`; - } - if (bytes < MB) { - return `${(bytes / KB).toFixed(2)} KB`; - } - if (bytes < GB) { - return `${(bytes / MB).toFixed(2)} MB`; - } - - return `${(bytes / GB).toFixed(2)} GB`; -} - -function toMarkdown(report: typeof relevantResults): string { - const header = [ - "Benchmark", "min", "max", "p25", "p50", "p75", "p99", "p999", "avg", "samples", "heap (avg)", "gc (avg)" - ]; - - const lines = [ - "# Benchmark Report", - "", - `- **Timestamp:** ${report.timestamp}`, - `- **Runtime:** ${report.runtime}`, - `- **CPU:** ${report.cpu.name} (~${report.cpu.freq.toFixed(2)} GHz)`, - "", - `| ${header.join(" | ")} |`, - `| ${header.map(() => "---").join(" | ")} |` - ]; - - for (const { name, stats } of report.benchmarks) { - const row = [ - name, - formatDuration(stats.min), - formatDuration(stats.max), - formatDuration(stats.p25), - formatDuration(stats.p50), - formatDuration(stats.p75), - formatDuration(stats.p99), - formatDuration(stats.p999), - formatDuration(stats.avg), - String(stats.ticks), - stats.heap ? formatBytes(stats.heap.avg) : "—", - stats.gc ? formatDuration(stats.gc.avg) : "—" - ]; - - lines.push(`| ${row.join(" | ")} |`); - } - - return lines.join("\n") + "\n"; -} From aac0d5c57b6fe07b222baf00e6a1dc14f79a518c Mon Sep 17 00:00:00 2001 From: Resham Pokhrel Date: Sun, 21 Jun 2026 22:27:50 -0500 Subject: [PATCH 06/11] test: add markdown generation specs --- workspaces/js-x-ray/test/markdown.spec.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 workspaces/js-x-ray/test/markdown.spec.ts diff --git a/workspaces/js-x-ray/test/markdown.spec.ts b/workspaces/js-x-ray/test/markdown.spec.ts new file mode 100644 index 00000000..6dddd463 --- /dev/null +++ b/workspaces/js-x-ray/test/markdown.spec.ts @@ -0,0 +1,10 @@ +// Import Node.js Dependencies +import assert from "node:assert"; +import { describe, test } from "node:test"; + +// Import Internal Dependencies +import { + formatDuration, + formatBytes, + toMarkdown +} from "../benchmark/markdown.ts"; \ No newline at end of file From a062fbdcb99d6c1d0899fea55037e6c3095bb14f Mon Sep 17 00:00:00 2001 From: Resham Pokhrel Date: Sun, 21 Jun 2026 22:29:30 -0500 Subject: [PATCH 07/11] test: add three test cases for markdown generation --- workspaces/js-x-ray/test/markdown.spec.ts | 153 +++++++++++++++++++++- 1 file changed, 152 insertions(+), 1 deletion(-) diff --git a/workspaces/js-x-ray/test/markdown.spec.ts b/workspaces/js-x-ray/test/markdown.spec.ts index 6dddd463..f4501784 100644 --- a/workspaces/js-x-ray/test/markdown.spec.ts +++ b/workspaces/js-x-ray/test/markdown.spec.ts @@ -7,4 +7,155 @@ import { formatDuration, formatBytes, toMarkdown -} from "../benchmark/markdown.ts"; \ No newline at end of file +} from "../benchmark/markdown.ts"; + +describe("formatDuration", () => { + test("should format values below 1,000 as nanoseconds", () => { + assert.strictEqual(formatDuration(0), "0.00 ns"); + assert.strictEqual(formatDuration(500), "500.00 ns"); + assert.strictEqual(formatDuration(999), "999.00 ns"); + }); + + test("should format values from 1,000 to 999,999 as microseconds", () => { + assert.strictEqual(formatDuration(1_000), "1.00 µs"); + assert.strictEqual(formatDuration(1_500), "1.50 µs"); + assert.strictEqual(formatDuration(999_999), "1000.00 µs"); + }); + + test("should format values from 1,000,000 to 999,999,999 as milliseconds", () => { + assert.strictEqual(formatDuration(1_000_000), "1.00 ms"); + assert.strictEqual(formatDuration(5_500_000), "5.50 ms"); + assert.strictEqual(formatDuration(999_999_999), "1000.00 ms"); + }); + + test("should format values at or above 1,000,000,000 as seconds", () => { + assert.strictEqual(formatDuration(1_000_000_000), "1.00 s"); + assert.strictEqual(formatDuration(2_500_000_000), "2.50 s"); + }); +}); + +describe("formatBytes", () => { + test("should format values below 1,024 as bytes", () => { + assert.strictEqual(formatBytes(0), "0 B"); + assert.strictEqual(formatBytes(512), "512 B"); + assert.strictEqual(formatBytes(1_023), "1023 B"); + }); + + test("should format values from 1,024 to 1,048,575 as KB", () => { + assert.strictEqual(formatBytes(1_024), "1.00 KB"); + assert.strictEqual(formatBytes(1_536), "1.50 KB"); + }); + + test("should format values from 1,048,576 to 1,073,741,823 as MB", () => { + assert.strictEqual(formatBytes(1_048_576), "1.00 MB"); + assert.strictEqual(formatBytes(5_242_880), "5.00 MB"); + }); + + test("should format values at or above 1,073,741,824 as GB", () => { + assert.strictEqual(formatBytes(1_073_741_824), "1.00 GB"); + assert.strictEqual(formatBytes(2_684_354_560), "2.50 GB"); + }); +}); + +describe("toMarkdown", () => { + const baseReport = { + timestamp: "2025-01-15T12:00:00.000Z", + runtime: "node v24.0.0", + cpu: { name: "Apple M1", freq: 3.20 } + }; + + test("should render the header section with metadata", () => { + const md = toMarkdown({ ...baseReport, benchmarks: [] }); + + assert.ok(md.startsWith("# Benchmark Report\n")); + assert.ok(md.includes("- **Timestamp:** 2025-01-15T12:00:00.000Z")); + assert.ok(md.includes("- **Runtime:** node v24.0.0")); + assert.ok(md.includes("- **CPU:** Apple M1 (~3.20 GHz)")); + }); + + test("should render the table header and separator rows", () => { + const md = toMarkdown({ ...baseReport, benchmarks: [] }); + const lines = md.split("\n"); + + const headerLine = lines.find((l) => l.startsWith("| Benchmark")); + assert.ok(headerLine); + assert.ok(headerLine.includes("heap (avg)")); + assert.ok(headerLine.includes("gc (avg)")); + + const separatorLine = lines.find((l) => l.startsWith("| ---")); + assert.ok(separatorLine); + }); + + test("should use — fallback when heap and gc are absent", () => { + const md = toMarkdown({ + ...baseReport, + benchmarks: [{ + name: "test-bench", + stats: { + min: 100, max: 200, p25: 120, p50: 150, + p75: 180, p99: 195, p999: 199, avg: 150, + ticks: 1000 + } + }] + }); + + const dataLine = md.split("\n").find((l) => l.includes("test-bench")); + assert.ok(dataLine); + + const cells = dataLine.split("|").map((c) => c.trim()).filter(Boolean); + // heap (avg) is column 11, gc (avg) is column 12 + assert.strictEqual(cells[10], "—"); + assert.strictEqual(cells[11], "—"); + }); + + test("should render heap and gc values when present", () => { + const md = toMarkdown({ + ...baseReport, + benchmarks: [{ + name: "test-bench", + stats: { + min: 1_000_000, max: 2_000_000, + p25: 1_200_000, p50: 1_500_000, + p75: 1_800_000, p99: 1_950_000, + p999: 1_990_000, avg: 1_500_000, + ticks: 500, + heap: { avg: 5_242_880 }, + gc: { avg: 50_000 } + } + }] + }); + + const dataLine = md.split("\n").find((l) => l.includes("test-bench")); + assert.ok(dataLine); + + const cells = dataLine.split("|").map((c) => c.trim()).filter(Boolean); + assert.strictEqual(cells[10], "5.00 MB"); + assert.strictEqual(cells[11], "50.00 µs"); + }); + + test("should render multiple benchmark rows", () => { + const stats = { + min: 100, max: 200, p25: 120, p50: 150, + p75: 180, p99: 195, p999: 199, avg: 150, + ticks: 1000 + }; + + const md = toMarkdown({ + ...baseReport, + benchmarks: [ + { name: "bench-a", stats }, + { name: "bench-b", stats } + ] + }); + + const lines = md.split("\n"); + assert.ok(lines.some((l) => l.includes("bench-a"))); + assert.ok(lines.some((l) => l.includes("bench-b"))); + }); + + test("should end with a trailing newline", () => { + const md = toMarkdown({ ...baseReport, benchmarks: [] }); + + assert.ok(md.endsWith("\n")); + }); +}); From cd43af41108c3f1757556ef356019f02cdd03ad2 Mon Sep 17 00:00:00 2001 From: Resham Pokhrel Date: Mon, 22 Jun 2026 14:05:42 -0500 Subject: [PATCH 08/11] feat(benchmark)!: replace report.json with report.md table BREAKING CHANGE: benchmark results are now written only as a Markdown table (report.md); report.json and its generation code have been removed. --- workspaces/js-x-ray/benchmark/report.json | 269 ------------------ .../js-x-ray/benchmark/write-snapshot.ts | 3 - 2 files changed, 272 deletions(-) delete mode 100644 workspaces/js-x-ray/benchmark/report.json diff --git a/workspaces/js-x-ray/benchmark/report.json b/workspaces/js-x-ray/benchmark/report.json deleted file mode 100644 index 15351cdc..00000000 --- a/workspaces/js-x-ray/benchmark/report.json +++ /dev/null @@ -1,269 +0,0 @@ -{ - "timestamp": "2026-06-22T02:23:51.314Z", - "runtime": "node", - "cpu": { - "name": "unknown", - "freq": 3.0750483158698763 - }, - "benchmarks": [ - { - "stats": { - "kind": "fn", - "min": 233750, - "max": 982459, - "p25": 245750, - "p50": 256542, - "p75": 270917, - "p99": 452833, - "p999": 783041, - "avg": 266753.44935262756, - "ticks": 2626, - "heap": { - "_": 2046, - "total": 559628528, - "min": 2256, - "max": 2758736, - "avg": 273523.22971652006 - } - }, - "args": {}, - "name": "Small File (jscrush.js - 1.06KB)" - }, - { - "stats": { - "kind": "fn", - "min": 596291, - "max": 1789375, - "p25": 627125, - "p50": 641834, - "p75": 661708, - "p99": 1025291, - "p999": 1207750, - "avg": 660613.7892249527, - "ticks": 1058, - "heap": { - "_": 935, - "total": 407804752, - "min": 1536, - "max": 3052640, - "avg": 436154.814973262 - } - }, - "args": {}, - "name": "Small File (npm-audit.js - 1.51KB)" - }, - { - "stats": { - "kind": "fn", - "min": 1486416, - "max": 3350500, - "p25": 1507958, - "p50": 1530875, - "p75": 1588917, - "p99": 2835541, - "p999": 3311625, - "avg": 1595889.388505747, - "ticks": 435, - "heap": { - "_": 428, - "total": 292233552, - "min": 36232, - "max": 1995208, - "avg": 682788.6728971963 - } - }, - "args": {}, - "name": "Small File (forbes-skimmer.js - 2.20KB)" - }, - { - "stats": { - "kind": "fn", - "min": 1233541, - "max": 2995792, - "p25": 1262875, - "p50": 1289459, - "p75": 1329250, - "p99": 2573000, - "p999": 2799584, - "avg": 1348236.1805825243, - "ticks": 515, - "heap": { - "_": 500, - "total": 357976488, - "min": 66512, - "max": 2587224, - "avg": 715952.976 - } - }, - "args": {}, - "name": "Small File (rate-map.js - 2.30KB)" - }, - { - "stats": { - "kind": "fn", - "min": 1713500, - "max": 2967792, - "p25": 1755000, - "p50": 1776750, - "p75": 1824417, - "p99": 2658000, - "p999": 2823875, - "avg": 1827884.2295514513, - "ticks": 379, - "heap": { - "_": 377, - "total": 336534728, - "min": 82240, - "max": 2313544, - "avg": 892665.0610079576 - } - }, - "args": {}, - "name": "Small File (event-stream.js - 3.84KB)" - }, - { - "stats": { - "kind": "fn", - "min": 1056250, - "max": 3197333, - "p25": 1091999.9999990463, - "p50": 1116292, - "p75": 1164375, - "p99": 1912250, - "p999": 2935625.0000009537, - "avg": 1168175.332214786, - "ticks": 596, - "heap": { - "_": 582, - "total": 453112688, - "min": 95256, - "max": 2084296, - "avg": 778544.1374570447 - } - }, - "args": {}, - "name": "Small File (modrrnize.js - 9.31KB)" - }, - { - "stats": { - "kind": "fn", - "min": 1063666, - "max": 2262292, - "p25": 1083666, - "p50": 1099792, - "p75": 1130375, - "p99": 1721333, - "p999": 1978084, - "avg": 1137614.290849673, - "ticks": 612, - "heap": { - "_": 601, - "total": 459221464, - "min": 145376, - "max": 2236544, - "avg": 764095.6139767055 - } - }, - "args": {}, - "name": "Small File (smith.js - 9.31KB)" - }, - { - "stats": { - "kind": "fn", - "min": 2352459, - "max": 4936250, - "p25": 2387167, - "p50": 2403292, - "p75": 2465291, - "p99": 4659208, - "p999": 4828500, - "avg": 2504388.6145454547, - "ticks": 275, - "heap": { - "_": 273, - "total": 382511704, - "min": 2344, - "max": 3340776, - "avg": 1401141.772893773 - } - }, - "args": {}, - "name": "Medium File (kopiluwak.js - 15.53KB)" - }, - { - "stats": { - "kind": "fn", - "min": 76615541, - "max": 81810917, - "p25": 78609833, - "p50": 79120000, - "p75": 79922875, - "p99": 81716542, - "p999": 81716542, - "avg": 79406102.27272727, - "ticks": 11, - "heap": { - "_": 15, - "total": 492130520, - "min": 27769928, - "max": 34951936, - "avg": 32808701.333333332 - }, - "gc": { - "total": 120333333, - "min": 6681541, - "max": 12206583, - "avg": 8022222.2 - } - }, - "args": {}, - "name": "Large File (obfuscate.js - 89.57KB)" - }, - { - "stats": { - "kind": "fn", - "min": 245083, - "max": 961792, - "p25": 263333, - "p50": 276666, - "p75": 296292, - "p99": 515917, - "p999": 886625, - "avg": 291390.227953411, - "ticks": 2404, - "heap": { - "_": 1865, - "total": 506157440, - "min": 1728, - "max": 1605112, - "avg": 271398.09115281503 - } - }, - "args": {}, - "name": "jscrush.js" - }, - { - "stats": { - "kind": "fn", - "min": 52208417, - "max": 58259916, - "p25": 53704167, - "p50": 54129458, - "p75": 54798500, - "p99": 56464833, - "p999": 56464833, - "avg": 54452370.222222224, - "ticks": 9, - "heap": { - "_": 9, - "total": 193557832, - "min": 18627040, - "max": 30725312, - "avg": 21506425.777777776 - } - }, - "args": {}, - "name": "obfuscate.js" - } - ] -} \ No newline at end of file diff --git a/workspaces/js-x-ray/benchmark/write-snapshot.ts b/workspaces/js-x-ray/benchmark/write-snapshot.ts index 2eeb5380..23037221 100644 --- a/workspaces/js-x-ray/benchmark/write-snapshot.ts +++ b/workspaces/js-x-ray/benchmark/write-snapshot.ts @@ -5,7 +5,6 @@ import { writeFileSync } from "node:fs"; import { benchmark } from "./bench.ts"; import { toMarkdown } from "./markdown.ts"; -const kReportURL = new URL("report.json", import.meta.url); const kReportMarkdownURL = new URL("report.md", import.meta.url); const results = await benchmark(); @@ -32,7 +31,5 @@ const relevantResults = { }) }; -writeFileSync(kReportURL, JSON.stringify(relevantResults, null, 2)); - // Human-readable snapshot as a Markdown table. writeFileSync(kReportMarkdownURL, toMarkdown(relevantResults)); From 080aa966f70a99b6529139cd232fe9e0f1141853 Mon Sep 17 00:00:00 2001 From: Resham Pokhrel Date: Mon, 22 Jun 2026 14:21:21 -0500 Subject: [PATCH 09/11] test(benchmark): remove formatDuration and formatBytes specs --- workspaces/js-x-ray/test/markdown.spec.ts | 54 +---------------------- 1 file changed, 1 insertion(+), 53 deletions(-) diff --git a/workspaces/js-x-ray/test/markdown.spec.ts b/workspaces/js-x-ray/test/markdown.spec.ts index f4501784..0e6d62d3 100644 --- a/workspaces/js-x-ray/test/markdown.spec.ts +++ b/workspaces/js-x-ray/test/markdown.spec.ts @@ -3,59 +3,7 @@ import assert from "node:assert"; import { describe, test } from "node:test"; // Import Internal Dependencies -import { - formatDuration, - formatBytes, - toMarkdown -} from "../benchmark/markdown.ts"; - -describe("formatDuration", () => { - test("should format values below 1,000 as nanoseconds", () => { - assert.strictEqual(formatDuration(0), "0.00 ns"); - assert.strictEqual(formatDuration(500), "500.00 ns"); - assert.strictEqual(formatDuration(999), "999.00 ns"); - }); - - test("should format values from 1,000 to 999,999 as microseconds", () => { - assert.strictEqual(formatDuration(1_000), "1.00 µs"); - assert.strictEqual(formatDuration(1_500), "1.50 µs"); - assert.strictEqual(formatDuration(999_999), "1000.00 µs"); - }); - - test("should format values from 1,000,000 to 999,999,999 as milliseconds", () => { - assert.strictEqual(formatDuration(1_000_000), "1.00 ms"); - assert.strictEqual(formatDuration(5_500_000), "5.50 ms"); - assert.strictEqual(formatDuration(999_999_999), "1000.00 ms"); - }); - - test("should format values at or above 1,000,000,000 as seconds", () => { - assert.strictEqual(formatDuration(1_000_000_000), "1.00 s"); - assert.strictEqual(formatDuration(2_500_000_000), "2.50 s"); - }); -}); - -describe("formatBytes", () => { - test("should format values below 1,024 as bytes", () => { - assert.strictEqual(formatBytes(0), "0 B"); - assert.strictEqual(formatBytes(512), "512 B"); - assert.strictEqual(formatBytes(1_023), "1023 B"); - }); - - test("should format values from 1,024 to 1,048,575 as KB", () => { - assert.strictEqual(formatBytes(1_024), "1.00 KB"); - assert.strictEqual(formatBytes(1_536), "1.50 KB"); - }); - - test("should format values from 1,048,576 to 1,073,741,823 as MB", () => { - assert.strictEqual(formatBytes(1_048_576), "1.00 MB"); - assert.strictEqual(formatBytes(5_242_880), "5.00 MB"); - }); - - test("should format values at or above 1,073,741,824 as GB", () => { - assert.strictEqual(formatBytes(1_073_741_824), "1.00 GB"); - assert.strictEqual(formatBytes(2_684_354_560), "2.50 GB"); - }); -}); +import { toMarkdown } from "../benchmark/markdown.ts"; describe("toMarkdown", () => { const baseReport = { From 6fa172efb48d1518ee6792a6ae513c4b83ad3ad0 Mon Sep 17 00:00:00 2001 From: Resham Pokhrel Date: Mon, 22 Jun 2026 15:10:41 -0500 Subject: [PATCH 10/11] refactor(markdown): remove export from formatDuration and formatBytes helpers --- workspaces/js-x-ray/benchmark/markdown.ts | 4 ++-- workspaces/js-x-ray/benchmark/report.md | 24 +++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/workspaces/js-x-ray/benchmark/markdown.ts b/workspaces/js-x-ray/benchmark/markdown.ts index e8307bdc..3e0c7a89 100644 --- a/workspaces/js-x-ray/benchmark/markdown.ts +++ b/workspaces/js-x-ray/benchmark/markdown.ts @@ -27,7 +27,7 @@ export interface BenchmarkReport { /** * mitata reports timings in nanoseconds. Picks the most readable unit. */ -export function formatDuration(nanoseconds: number): string { +function formatDuration(nanoseconds: number): string { if (nanoseconds < 1_000) { return `${nanoseconds.toFixed(2)} ns`; } @@ -44,7 +44,7 @@ export function formatDuration(nanoseconds: number): string { /** * heap stats are reported in bytes. */ -export function formatBytes(bytes: number): string { +function formatBytes(bytes: number): string { if (bytes < KB) { return `${bytes.toFixed(0)} B`; } diff --git a/workspaces/js-x-ray/benchmark/report.md b/workspaces/js-x-ray/benchmark/report.md index c466d65f..107ece89 100644 --- a/workspaces/js-x-ray/benchmark/report.md +++ b/workspaces/js-x-ray/benchmark/report.md @@ -1,19 +1,19 @@ # Benchmark Report -- **Timestamp:** 2026-06-22T02:23:51.314Z +- **Timestamp:** 2026-06-22T19:58:11.748Z - **Runtime:** node - **CPU:** unknown (~3.08 GHz) | Benchmark | min | max | p25 | p50 | p75 | p99 | p999 | avg | samples | heap (avg) | gc (avg) | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | -| Small File (jscrush.js - 1.06KB) | 233.75 µs | 982.46 µs | 245.75 µs | 256.54 µs | 270.92 µs | 452.83 µs | 783.04 µs | 266.75 µs | 2626 | 267.11 KB | — | -| Small File (npm-audit.js - 1.51KB) | 596.29 µs | 1.79 ms | 627.13 µs | 641.83 µs | 661.71 µs | 1.03 ms | 1.21 ms | 660.61 µs | 1058 | 425.93 KB | — | -| Small File (forbes-skimmer.js - 2.20KB) | 1.49 ms | 3.35 ms | 1.51 ms | 1.53 ms | 1.59 ms | 2.84 ms | 3.31 ms | 1.60 ms | 435 | 666.79 KB | — | -| Small File (rate-map.js - 2.30KB) | 1.23 ms | 3.00 ms | 1.26 ms | 1.29 ms | 1.33 ms | 2.57 ms | 2.80 ms | 1.35 ms | 515 | 699.17 KB | — | -| Small File (event-stream.js - 3.84KB) | 1.71 ms | 2.97 ms | 1.75 ms | 1.78 ms | 1.82 ms | 2.66 ms | 2.82 ms | 1.83 ms | 379 | 871.74 KB | — | -| Small File (modrrnize.js - 9.31KB) | 1.06 ms | 3.20 ms | 1.09 ms | 1.12 ms | 1.16 ms | 1.91 ms | 2.94 ms | 1.17 ms | 596 | 760.30 KB | — | -| Small File (smith.js - 9.31KB) | 1.06 ms | 2.26 ms | 1.08 ms | 1.10 ms | 1.13 ms | 1.72 ms | 1.98 ms | 1.14 ms | 612 | 746.19 KB | — | -| Medium File (kopiluwak.js - 15.53KB) | 2.35 ms | 4.94 ms | 2.39 ms | 2.40 ms | 2.47 ms | 4.66 ms | 4.83 ms | 2.50 ms | 275 | 1.34 MB | — | -| Large File (obfuscate.js - 89.57KB) | 76.62 ms | 81.81 ms | 78.61 ms | 79.12 ms | 79.92 ms | 81.72 ms | 81.72 ms | 79.41 ms | 11 | 31.29 MB | 8.02 ms | -| jscrush.js | 245.08 µs | 961.79 µs | 263.33 µs | 276.67 µs | 296.29 µs | 515.92 µs | 886.63 µs | 291.39 µs | 2404 | 265.04 KB | — | -| obfuscate.js | 52.21 ms | 58.26 ms | 53.70 ms | 54.13 ms | 54.80 ms | 56.46 ms | 56.46 ms | 54.45 ms | 9 | 20.51 MB | — | +| Small File (jscrush.js - 1.06KB) | 235.54 µs | 931.33 µs | 248.63 µs | 259.33 µs | 273.92 µs | 477.83 µs | 814.42 µs | 270.78 µs | 2586 | 270.78 KB | — | +| Small File (npm-audit.js - 1.51KB) | 600.63 µs | 1.57 ms | 631.00 µs | 644.04 µs | 660.63 µs | 1.03 ms | 1.13 ms | 661.85 µs | 1056 | 429.21 KB | — | +| Small File (forbes-skimmer.js - 2.20KB) | 1.50 ms | 3.49 ms | 1.53 ms | 1.55 ms | 1.60 ms | 2.82 ms | 3.12 ms | 1.61 ms | 430 | 666.61 KB | — | +| Small File (rate-map.js - 2.30KB) | 1.24 ms | 3.03 ms | 1.28 ms | 1.30 ms | 1.35 ms | 2.51 ms | 2.83 ms | 1.37 ms | 508 | 702.45 KB | — | +| Small File (event-stream.js - 3.84KB) | 1.74 ms | 3.23 ms | 1.78 ms | 1.81 ms | 1.86 ms | 2.44 ms | 2.89 ms | 1.85 ms | 374 | 878.08 KB | — | +| Small File (modrrnize.js - 9.31KB) | 1.05 ms | 2.34 ms | 1.08 ms | 1.10 ms | 1.14 ms | 1.82 ms | 2.14 ms | 1.15 ms | 607 | 757.93 KB | — | +| Small File (smith.js - 9.31KB) | 1.06 ms | 2.40 ms | 1.08 ms | 1.09 ms | 1.12 ms | 1.71 ms | 2.23 ms | 1.13 ms | 616 | 744.71 KB | — | +| Medium File (kopiluwak.js - 15.53KB) | 2.39 ms | 5.21 ms | 2.42 ms | 2.43 ms | 2.50 ms | 4.53 ms | 5.09 ms | 2.54 ms | 271 | 1.34 MB | — | +| Large File (obfuscate.js - 89.57KB) | 77.03 ms | 83.01 ms | 77.54 ms | 78.61 ms | 80.19 ms | 82.61 ms | 82.61 ms | 79.44 ms | 11 | 31.31 MB | 7.84 ms | +| jscrush.js | 248.00 µs | 931.00 µs | 263.17 µs | 275.21 µs | 290.88 µs | 527.92 µs | 890.13 µs | 288.19 µs | 2432 | 267.47 KB | — | +| obfuscate.js | 52.78 ms | 81.45 ms | 53.29 ms | 56.26 ms | 60.27 ms | 66.76 ms | 66.76 ms | 59.41 ms | 12 | 20.47 MB | — | From 8cbabd7d0e74f164c9785d118efe455ecbb97819 Mon Sep 17 00:00:00 2001 From: Resham Pokhrel Date: Mon, 22 Jun 2026 16:01:41 -0500 Subject: [PATCH 11/11] chore(changeset): add changeset for benchmark report.md --- .changeset/odd-rice-follow.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/odd-rice-follow.md diff --git a/.changeset/odd-rice-follow.md b/.changeset/odd-rice-follow.md new file mode 100644 index 00000000..acdd7297 --- /dev/null +++ b/.changeset/odd-rice-follow.md @@ -0,0 +1,5 @@ +--- +"@nodesecure/js-x-ray": patch +--- + +Store benchmark results in a readable Markdown table (report.md) instead of raw JSON.