Skip to content

refactor(benchmark-results): emit numeric values instead of strings - #465

Open
ilteoood wants to merge 1 commit into
fastify:mainfrom
ilteoood:feature/numeric-benchmark-results
Open

refactor(benchmark-results): emit numeric values instead of strings#465
ilteoood wants to merge 1 commit into
fastify:mainfrom
ilteoood:feature/numeric-benchmark-results

Conversation

@ilteoood

Copy link
Copy Markdown
Member

The committed benchmark-results.json and the file produced by
benchmark-compare.js had requests, latency, and throughput
encoded as strings (e.g. "54500.8") and "N/A" for missing
values. Numeric JSON consumers can't operate on those directly.

This change emits them as numbers (using Math.round with the same
decimal precision as before) and null when a metric is absent,
while keeping the rounding behaviour identical for present values.

-  const formatThroughput = throughput => throughput ? (throughput / 1024 / 1024).toFixed(2) : 'N/A'
+  const round = (value, decimals) => value ? Math.round(value * 10 ** decimals) / 10 ** decimals : null
...
-        requests: requests ? requests.toFixed(1) : 'N/A',
-        latency: latency ? latency.toFixed(2) : 'N/A',
-        throughput: formatThroughput(throughput)
+        requests: round(requests, 1),
+        latency: round(latency, 2),
+        throughput: round(throughput / 1024 / 1024, 2)

benchmark-results.json is regenerated to match so the checked-in
file stays consistent with the new format.

The output JSON now stores requests, latency, and throughput as numbers
(null for missing values) using the same decimal precision as before,
unblocking consumers that rely on numeric JSON.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant