Skip to content

Stabilize #[bench] and Bencher? #66287

Open
@SimonSapin

Description

@SimonSapin

I’ll take the liberty of copying a section of @hsivonen’s Rust 2020 blog post:

Non-Nightly Benchmarking

The library support for the cargo bench feature has been in the state “basically, the design is problematic, but we haven’t had anyone work through those issues yet” since 2015. It’s a useful feature nonetheless. Like I said a year ago and the year before, it’s time to let go of the possibility of tweaking it for elegance and just let users use it on non-nighly Rust.

Indeed the existing benchmarking support has basically not changed in years, and I’m not aware of anyone planning to work on it. To keep reserving the right to make breaking changes is not useful at this point. Custom test frameworks offer another way forward for when someone does want to work on better benchmarking.

So I’d like to propose a plan:

  • Move test::Bencher to std::bench::Bencher. I have a PR coming soon that Move test::Bencher to a new (unstable) std::bench module #66290 demonstrates that this is possible. This move avoids the need to stabilize the test crate.
  • Optionally, make some surface-only API tweaks to Bencher. For example, the public bytes field could become a parameter to some method.
    • Although not strictly necessary for changes to an unstable type, we can keep the existing bytes field and iter method unchanged as unstable + deprecated for a while.
  • Stabilize the #[bench] attribute and just enough of Bencher to make it usable with #[bench]. (For example, no stable constructor.)

@rust-lang/libs, @rust-lang/lang, do you feel this needs an RFC?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-libtestArea: `#[test]` / the `test` libraryB-unstableBlocker: Implemented in the nightly compiler and unstable.T-langRelevant to the language team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions