Benchfmt.rs: Bringing Go's benchmarking and benchstat workflow to Rust bwplotka....
HN Best 200 @best
Benchfmt.rs: Bringing Go's benchmarking and benchstat workflow to Rust bwplotka.dev · 19 points · 3 comments · HN thread
TL;DR Bartłomiej Płotka (Prometheus/Thanos maintainer) introduces benchfmt.rs, a zero-dependency Rust benchmark runner and a Criterion/libtest converter that emit Go's benchfmt format so benchstat can compare Rust and Go microbenchmarks. He benchmarks varint and Prometheus Remote Write 2.0 decoding, reporting Rust roughly 15-43% faster on time and fewer allocations at the 2,000-series size, but more allocated bytes. The post also covers pprof support and heap allocation counting per op.
- benchfmt.rs is a zero-dependency Rust benchmark runner that accepts the same CLI flags as go test -bench, adds a thread-local allocation counter (B/op, allocs/op), pprof profiling, and /key=value sub-benchmark names.
- A Criterion converter (benchfmt criterion target/criterion) turns existing Criterion output into Go benchfmt format so benchstat can build tables without editing benchmark code.
- On DecodeVarints, Rust ran at 4.90 µs/op vs Go's 8.54 µs/op (-42.56%); the post attributes the gap to LLVM unrolling the shift loop and to unsigned index bounds-check elimination.
- On DecodeRemoteWrite2 at 2,000 series, Rust was 17.68% faster and made 14.55% fewer heap allocations, but allocated 30.98% more bytes, mainly from Vec capacity doubling in prost.
- Criterion's linear-ramp sampling showed about ±5% variance versus ±1-2% for steady-state epochs; the author cites a compile-time cost of 42 extra transitive crates for Criterion.
- A standalone /usr/bin/time -v check found Rust used 1.9x to 3.2x less CPU and 3.8x to 4.4x less RAM per request than Go in the tested setup.
Discussion The comment thread is very small (three comments) and positive in tone. Commenters welcome the tool as something long needed for Rust benchmarking. The one substantive exchange points out that Michael Pratt from the Go team built a similar benchfmt converter about two years earlier, which the author acknowledges.
- Welcome: benchstat-style comparison for Rust is long overdue (many): Commenters respond with enthusiasm, calling the project 'sweet' and saying no one had done this before. Both comments are brief and carry no technical critique.
- Similar prior work already exists in Go's ecosystem (a few): One commenter points out that Michael Pratt from the Go team published a comparable converter, benchfmt-convert, about two years earlier. The author confirms this and credits that earlier work.
Links from the comments
#rust #golang #benchmarking #benchstat #performance #prometheus