Skip to content

fix: numeric median sort + show sub-ms time precision in charts#97

Merged
stormslowly merged 2 commits into
mainfrom
refactor/better_ms_format
May 15, 2026
Merged

fix: numeric median sort + show sub-ms time precision in charts#97
stormslowly merged 2 commits into
mainfrom
refactor/better_ms_format

Conversation

@stormslowly
Copy link
Copy Markdown
Contributor

Why

Two small precision fixes for benchmark stats and display:

  1. calcStatistics median is wrong for multi-digit values. values.sort() defaults to lexicographic string order, so e.g. [12, 9, 3] sorts to ["12", "3", "9"] and reports median = 3 instead of 9. min/max are unaffected because they use Math.min/Math.max.

  2. Chart formatTime truncates ms display to integer. Pairs with rspack fix(stats): preserve sub-millisecond precision in logger time entries rspack#14049 which makes logger.time emit sub-millisecond floats — without this change the chart axis and tooltip would still render 154 ms instead of 154.382 ms, hiding the µs-scale precision the data now carries.

Before / After

calcStatistics([12, 9, 3]).median  →  3       // before
calcStatistics([12, 9, 3]).median  →  9       // after

formatTime(0.019542)               →  "0 ms"     // before
formatTime(0.019542)               →  "0.020 ms" // after

values.sort() defaults to lexicographic string order, which produces a
wrong median as soon as a metric has 2+ digit values. E.g. [12, 9, 3]
would sort to ["12", "3", "9"] and report median = 3 instead of 9.
Pairs with rspack web-infra-dev/rspack#14049 which emits sub-ms
logger.time values; before this change the chart axis/tooltip rounded
those to integer ms and hid the µs-scale precision the data carries.
@stormslowly stormslowly merged commit 423ad4b into main May 15, 2026
4 checks passed
@stormslowly stormslowly deleted the refactor/better_ms_format branch May 15, 2026 09:14
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