-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
The benchmark harness runs a minimum of 300 iterations. #11010
Comments
related to #20142 |
This affects crypto-bench, in particular the PBKDF2 benchmarks. 300 seems like an arbitrary number, so it would be good to at least ensure that the minimum is based on some science. |
I have a benchmark with a long setup time, and this runs the setup 101 times. Running the benchmark inner loop a lot of times would be pretty bad, but all those setup runs is far worse: it takes ~6 minutes. For comparison, google benchmark (their C++ library) runs a comparable test setup once, and test 10 times, and takes about a second. |
I have a branch https://github.com/Craig-Macomber/rust/tree/fast_bench that fixes this. The statistics are a work in progress, but in its current state seems to work pretty well. Its enough to unblock my work with slow benchmarks, but don't trust the data from it, the confidence interval math wrong in a few different ways. This changes all the statistical logic, so its going to need some careful review before I even consider sending in a pull request. |
Perhaps we should add a per-benchmark limit from the command line, at least for now. |
To add another similar use case: I've found myself wishing I had a function to benchmark something just once (or a fixed number of times), e.g. #[bench]
fn foo_bench(b: &mut Bencher) {
b.once(|| {
// Do something slow and expensive
});
} Alternatively, perhaps libtest could allow for printing timings for the entire function. It could do that either by detecting that we're not calling #[bench]
fn foo_bench(_b: &mut Bencher) {
// Do something slow and expensive
} Of course, running something once arguably doesn't give very reliable timings. The motivation for this is twofold though:
|
I would like to track this as part of rust-lang/rfcs#816. That way we keep the standard test framework minimal while allowing libraries to develop more sophisticated custom test frameworks with knobs for number of iterations, access to statistics, control over CPU caches, etc. |
After the change to handle benches taking longer than 1 ms, the test runner will run a minimum of 50 + 5 * 50 iterations of the piece of code of interest. This should probably scale back for very slow functions (at the cost of statistical accuracy).
The text was updated successfully, but these errors were encountered: