← Wed, Nov 4 digest

Benchfmt.rs: Bringing Go's benchmarking and benchstat workflow to Rust

read article ↗ hn thread ↗

A developer built benchfmt.rs, bringing Go's benchstat workflow, heap allocation tracking, and CLI flags to Rust microbenchmarks to solve gaps in Criterion.

read it Essential reading for systems programmers frustrated by Criterion's lack of allocation tracking and incompatibility with benchstat.

summary

The author built benchfmt.rs to replicate Go's streamlined benchmarking and benchstat workflow in Rust, providing a zero-dependency runner with thread-local heap tracking and pprof integration. Using implementations of varint and Prometheus Remote Write 2.0 decoders in both languages, the post compares Criterion against the new native suite. The results highlight how Rust makes 14.5 percent fewer heap allocations than Go on complex payloads while consuming more heap bytes, insights invisible under standard Criterion setups.

key points

  1. benchfmt.rs provides a thread-local global allocator to track bytes and allocations per operation with zero atomic contention.
  2. Comparing Criterion's linear-ramp sampling to steady-state epochs shows the latter reduces benchmarking variance from plus-minus 5 percent down to 1 to 2 percent.
  3. While Rust made 14.5 percent fewer heap allocations than Go on the 2000-series Prometheus payload, it consumed 30.98 percent more total heap bytes due to layout differences.

who should read it

Rust and Go systems engineers and performance-sensitive developers looking for better A/B microbenchmarking workflows.

discussion warm

consensus

Commenters are highly enthusiastic about bringing Go's benchstat workflow and native allocation tracking to the Rust ecosystem.

pushback

A commenter raises a technical critique about whether benchstat's use of the Mann-Whitney U test implicitly assumes a location-shift that may not hold.

best comment by syntacticsalt ↗

As far as I could tell, benchstat seems to implicitly make a location-shift assumption in its interpretation of the Mann-Whitney U test, and I don't see why that assumption would hold.

It provides a nuanced statistical critique regarding benchstat's underlying assumptions when interpreting benchmark variance.

Generated by an LLM from the article and thread. Check the sources before relying on it.