-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fix benchmarks in library/core with black_box #107598
Conversation
r? @thomcc (rustbot has picked a reviewer for you, use r? to override) |
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
library/core/benches/char/methods.rs
Outdated
|
||
const CHARS: [char; 9] = ['0', 'x', '2', '5', 'A', 'f', '7', '8', '9']; | ||
const RADIX: [u32; 5] = [2, 8, 10, 16, 32]; | ||
|
||
#[bench] | ||
fn bench_to_digit_radix_2(b: &mut Bencher) { | ||
b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| c.to_digit(2)).min()) | ||
b.iter(|| black_box(CHARS.iter().cycle().take(10_000).map(|c| black_box(c).to_digit(2)).min())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to put a black_box
on the output, as it is automatically added by the Bencher
interface: https://github.com/rust-lang/rust/blob/1.67.0/library/test/src/bench.rs#L117. The important part (for the output) is that the lambda function passed as argument to .iter()
returns a non-()
result (which is already the case here).
The black_box
is definitely relevant for the input though :)
080e851
to
fe84cec
Compare
@rustbot ready |
Looks good. @bors r+ rollup |
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#106575 (Suggest `move` in nested closure when appropriate) - rust-lang#106805 (Suggest `{var:?}` when finding `{?:var}` in inline format strings) - rust-lang#107500 (Add tests to assert current behavior of large future sizes) - rust-lang#107598 (Fix benchmarks in library/core with black_box) - rust-lang#107602 (Parse and recover from type ascription in patterns) - rust-lang#107608 (Use triple rather than arch for fuchsia test-runner) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Fixes #107590