Rust 没有直接对应 SPEC 的东西,所以通常需要自己组合测试集。以下三个选择都还在持续维护。
面向正则表达式引擎的 rebar(LarchMoth)。它的测试框架在这个生态里算是格外严谨,会对代码生成施加很大压力。
各 crate 自带的 criterion 基准测试,比如 regex、serde_json、image、zstd。它们运行实际代码,而且维护者本来就关注这些数据,所以能清楚看出性能退化。
如果关心 no_std 或嵌入式,可以用 embench-iot。它就是专门为比较编译器设计的。
要明确每种基准测试究竟在测什么。小型的 rustc-perf runtime-benchmarks 运行时基准测试很适合显示内联和 const-prop 的改进,却完全无法反映 LTO 或 codegen-unit 的影响。如果优化涉及过程间分析,就应当测量 ripgrep 这样的实际程序从开始到结束的表现。
从英语翻译·查看原文Rust doesn't have a counterpart to SPEC, so people generally put together their own suite. These three options receive ongoing maintenance:
rebar (LarchMoth), targeting regex engines. Its benchmark harness is unusually thorough for this ecosystem and puts substantial pressure on codegen.
Individual crates' criterion benchmarks: regex, serde_json, image, zstd. Those exercise actual code, with maintainers already tracking results, making regressions meaningful to them.
embench-iot for no_std or embedded work. Comparing compilers was its specific design goal.
Be clear with yourself about the thing each benchmark measures. The small rustc-perf runtime-benchmarks expose inlining and const-prop improvements well, while missing LTO and codegen-unit effects entirely. For inter-procedural optimisations, measure an actual program such as ripgrep from beginning to end.