-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracking issue for #[bench] and benchmarking support #29553
Comments
Nominating for discussion in 1.6, and cc https://internals.rust-lang.org/t/bench-status/2122/10, a thread about this. I've currently extracted libtest and I would personally like to deprecate |
I like IMO it would be nice to be able to provide custom providers for |
Yeah my feeling here is that I wouldn't want to stabilize anything in the compiler itself unless it looks like a generic "custom test framework" infrastructure, but that's unfortunately a big undertaking that may take awhile. As a result my personal preference is to deprecate the support in the meantime for technically-the-same-if-not-quite-as-easy-to-use support on crates.io |
The libs team decided to punt on this for 1.6 |
This looks like it might be a good replacement for the current I agree with Alex that deprecation is the best resolution. |
The word upstream is that the unstable builtin benchmark tests are likely to be deprecated (rust-lang/rust#29553), but I didn't feel like learning Criterion just for this. test inference::triangle::tests::concerning_the_expense_of_computing_entropy ... bench: 0 ns/iter (+/- 0) test inference::triangle::tests::concerning_the_expense_of_updating ... bench: 1,485,967 ns/iter (+/- 81,055) I'm not sure how to interpret the zero for computing the entropy; I assume some sort of clever LLVM optimization has sloughed off the work to compile time. But yeah, that 1.5 million nanoseconds to do an update is way too explosive for a hotspot like `value_of_information`. We're going to need some new techniques.
This just came up on IRC and should be a consideration for anything we do here. Allowing for "unbenchmarked" parts of an iteration. The specific case this came up for was benchmarking an in-place sorting algorithm. Since performance is going to be different for sorted vs. unsorted lists, you need to clone the list each iteration which can throw off the results. |
The `#[bench]` attribute is [currently unstable][1], and is only usable on nightly Rust. However, being able to benchmark code with `cargo bench` is very useful functionality when writing performance-focused code, and something that the Cargo documentation currently glosses over. Some useful information on how to get benchmark tests up and running, with necessary caveats about stability, would likely be very helpful to new users. [1]: rust-lang/rust#29553
I'm sorry, but this is still required in nightly 1.20. If I write:
Rust complains that it can't find |
@fschutt That is correct, benchmarking with |
What's the current status of this given the recent discussion here? Is there another ongoing discussion somewhere else? |
Latest development seems to be rust-lang/rfcs#2318 |
Triage: no major movement recently |
This has been discussed numerous times across various RFCs and internals threads over the last ~7 years (and probably before then, too), and the latest 'next step' towards stabilization here seems to be the custom test frameworks RFC (tracked in #50297). That RFC and implementation seem unlikely to be pushed over the finish line -- even for a working, usable nightly implementation -- on any relatively short timescale, so I would like to suggest that we discuss whether the existing bench API could be minimally stabilized essentially as-is (listed in the issue description). It has a number of extensions that users have asked for historically, some already implemented:
The majority of these seem relatively feasible to either add to libtest or develop out of tree (e.g., in crates like criterion), but also look to me like extensible design atop the very simple interface we have today which has -- largely -- worked fine for the majority of basic use cases. A relatively fast skim through of the various RFCs to me suggest that the main objection to just stabilizing in place has always been more general designs or concerns about a forever stable piece of the language. Ultimately, it seems to me that a few functions and an attribute (which could have a different meaning or multiple meanings in the future) are not that painful to commit to. For example, we could, I think, easily imagine that The stabilization would mean stable access to the test crate, which I believe today is entirely unstable, so one alternative would be to move Bencher to std::test, re-exporting it in test. |
@Mark-Simulacrum as far as I can see the only part that the language has to support is preventing optimizations - stabilizing |
Like |
black_box is separately tracked by #64102 these days and is not necessary for a baseline stabilization (the closure return value is already passed through a black box, IIRC). FWIW, I don't personally see bench as distinct from test there -- they both share nearly all of the same infrastructure in the compiler and libtest. If we wanted to make test the only special attribute and require |
Given that the custom test frameworks experiment has been closed, how does @rust-lang/lang and @rust-lang/libs-api feel about either:
|
This is a tracking issue for the
#[bench]
attribute and its stability in the compiler. Currently it is not possible to use this from stable Rust as it requiresextern crate test
which is itself not stable.Core APIs for benchmarking:
#[bench]
, which means the function should take a&mut Bencher
argument and will be run as part of regular tests (and specifically benchmarked with --bench passed to the test binary).The text was updated successfully, but these errors were encountered: