Skip to content

Read the units BenchmarkDotNet writes into the CSV cells - #44

Merged
FlorianRappl merged 1 commit into
AngleSharp:develfrom
michaelthyregod:fix/compare-builds-units
Nov 2, 2026
Merged

FlorianRappl merged 1 commit into
AngleSharp:develfrom
michaelthyregod:fix/compare-builds-units

Conversation

@michaelthyregod

Copy link
Copy Markdown
Contributor

Compare-Builds.ps1 misread the BenchmarkDotNet CSV reports, so summary.md could be wrong.

Problem

Write-Summary stripped everything but digits and dots from the Mean and Allocated cells, then read them as ns and B. BenchmarkDotNet writes the unit into each cell and picks it per row (952.654 μs, 1,280.41 KB). So:

  • such rows were off by 1000x or 1024x;
  • a ratio was wrong whenever two builds of the same case landed in different units.

Change

  • Each cell is parsed as a value and a unit, then converted. Times: ns, μs/µs/us, ms, s. Sizes: B, KB, MB, GB.
    • NA (a failed benchmark) drops the row.
    • - counts as no allocation.
    • An unknown unit throws instead of producing a wrong number.
  • Reports are read only from this run's round-* folders. The baseline source trees live in the output directory too, and a report left in one of them would otherwise count as a build.

Verification

No benchmark run was needed: the script's functions were tested directly.

  • Cells: 12 samples convert correctly, across every unit, with thousands separators and -; an unknown unit is rejected.
  • Real data: on the reports of an earlier three-way run, the regenerated summary.md is identical to the original, even with a stray report in a source tree.
  • Mixed units: with one build's cells rewritten into μs/ms and KB/MB, the summary matches up to the rounding of the rewritten values. The previous parsing got 20 of 24 rows wrong; for example, 5.53 ms showed as "5.5 ns" with ratio 0.000.

🤖 Generated with Claude Code

Write-Summary stripped everything but digits and dots from the Mean and
Allocated cells and read them as ns and B. BenchmarkDotNet writes the
unit into each cell and picks it per row (952.654 us, 1,280.41 KB), so
such rows were off by 1000x or 1024x, and a ratio was wrong whenever two
builds of a case landed in different units.

Each cell is now parsed as a value and a unit (ns, us with the Greek mu,
the micro sign or u, ms, s; B, KB, MB, GB) and converted; NA (a failed
benchmark) drops the row, - counts as no allocation, and an unknown unit
throws. Reports are only read from this run's round-* folders, as a
report left in a baseline source tree would otherwise count as a build.

On the reports of an earlier three-way run the summary is unchanged; with
one build's cells rewritten into us/ms and KB/MB it matches up to the
rounding of the rewritten values, where the previous parsing got 20 of 24
rows wrong.
@FlorianRappl
FlorianRappl merged commit f956887 into AngleSharp:devel Nov 2, 2026
5 checks passed
@michaelthyregod
michaelthyregod deleted the fix/compare-builds-units branch November 3, 2026 06:10
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.

2 participants