Technology1 min read

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

By · Published by Everything Blog

In short

The benchfmt.rs project provides a zero-dependency benchmark runner alongside a converter that transforms output from Criterion and libtest suites into Go's benchfmt format. It incorporates key-value projections and tracks thread-local allocated bytes and objects per operation using identical flags to the "go test -bench" command. The system demonstrated its cross-language workflow by testing an unsigned LEB128 varint decoder and Prometheus Remote Write 2.0 HTTP body decoders.

Key points

  • Rust developers can run comparative workflows using the exact command-line interface flag…: Rust developers can run comparative workflows using the exact command-line interface flags found in Go.
  • Real-world validation was conducted using an unsigned LEB128 varint decoder and Prometheu…: Real-world validation was conducted using an unsigned LEB128 varint decoder and Prometheus Remote Write 2.0 workloads.
  • All benchmark test code and raw output files are publicly hosted in the bwplotka/benchmar…: All benchmark test code and raw output files are publicly hosted in the bwplotka/benchmarks repository.

Sources checked by our analysis pipeline: 1

TL;DR: I built

benchfmt.rs

, a zero-dependency Rust benchmark runner andCriterion

converter for Go’sbenchstat

. It adds/key=value

projections, heap tracking for allocated bytes (B/op

) and objects (allocs/op

) per op, andpprof

profiling.In this post, I am benchmarking

varint

and Prometheus Remote Write 2.0 decoding across Go and Rust to showcase the benefits ofbenchstat

-like flow in Rust. I’m also sharing some fun learnings on the way (e.g., yes Rust is faster).

Recently, I’ve been working on a few Rust projects across Google and open source. I came to Rust after years of writing performance-sensitive Go in Prometheus, Thanos, and teaching Go in the “Efficient Go” book. For me, much of Rust’s performance story is really good, until…. I wanted to run A/B microbenchmarks.

Perhaps I was spoiled by the Go benchmarking ecosystem, with the go tool -bench

and benchstat

in the center. To me, Rust standard benchmarking tools are lacking:

- Standard format for case comparison projections.

- Standard heap allocation measurements.

- Standard

pprof

support. - Simple to understand reliability scoring.

DISCLAIMER: A

standard

here means something that…

Technology