开发者 Bartłomiej Plotka(bwplotka)发布了 benchfmt.rs,这是一个零依赖的 Rust 基准测试运行器和转换工具,旨在将 Go 生态系统中流行的 go test -bench 和 benchstat 工作流引入 Rust 1。该工具支持线程本地堆内存分配追踪(统计 B/op 和 allocs/op)、pprof 分析以及生成与 Go benchfmt 格式兼容的输出,从而简化 Go 与 Rust 之间的 A/B 微基准测试对比 1。此外,它包含一个 Criterion/libtest 转换器,可直接输出 Go 的 benchfmt 格式以便使用 benchstat 进行分析 1。
文章通过 Prometheus Remote Write 2.0 和 varint 解码的实际案例展示了该工具的应用 1。在 DecodeVarints 基准测试中,Rust 比 Go 快 42.56%(4.90 µs vs 8.536 µs)1。在 DecodeRemoteWrite2 (2000 series) 测试中,Rust 比 Go 快 17.68%,但分配的堆字节数多 30.98%(2.05 MiB vs 1.568 MiB),而堆分配对象数量少 14.55%(16,490 vs 19,300 allocs/op)1。
Go 的背景垃圾回收 (GC) 导致其 CPU 占用率显著高于 Rust,例如在全核运行时高达 220% CPU,而 Rust 保持在约 99% 单核利用率 1。Rust 的高内存占用主要源于 prost crate 中 Vec 的容量倍增策略(capacity doubling),而非实际数据结构的大小 1。
Developer Bartłomiej Plotka has released benchfmt.rs, a zero-dependency Rust benchmark runner and converter designed to bring the popular go test -bench and benchstat workflow from the Go ecosystem into Rust 1. The tool features thread-local heap allocation counters that track metrics such as bytes per operation (B/op) and allocations per operation (allocs/op), along with integrated pprof analysis capabilities 1. It includes a converter for Criterion and libtest benchmarks that outputs data directly in Go’s compatible benchfmt format, enabling statistical comparison using Go’s existing benchstat utility 1. This infrastructure simplifies A/B micro-benchmark comparisons between Go and Rust implementations by standardizing output formats and measurement methodologies 1.
Practical demonstrations involving Prometheus Remote Write 2.0 and varint decoding highlight distinct performance trade-offs between the two languages 1. In the DecodeVarints benchmark, Rust outperformed Go by 42.56%, completing the task in 4.90 µs compared to Go’s 8.536 µs 1. For the DecodeRemoteWrite2 benchmark processing 2,000 series, Rust was 17.68% faster than Go but exhibited a 30.98% higher heap byte allocation at 2.05 MiB versus Go’s 1.568 MiB 1. Despite the increased memory volume, Rust achieved a 14.55% reduction in the number of heap allocation objects, recording 16,490 allocs/op against Go’s 19,300 allocs/op 1. The source attributes Rust’s higher memory footprint primarily to the capacity doubling strategy used by vectors in the prost crate, rather than the inherent size of the underlying data structures 1. Additionally, Go’s background garbage collector resulted in significantly higher CPU utilization, reaching up to 220% when running across all cores, whereas Rust maintained approximately 99% single-core usage 1.
评论
还没有评论,欢迎留下第一条。