Skip to content
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

Merged
merged 1 commit into from
Feb 3, 2023

Conversation

chenyukang
Copy link
Member

Fixes #107590

@rustbot
Copy link
Collaborator

rustbot commented Feb 2, 2023

r? @thomcc

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 2, 2023
@rustbot
Copy link
Collaborator

rustbot commented Feb 2, 2023

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs


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()))
Copy link

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 :)

@thomcc
Copy link
Member

thomcc commented Feb 2, 2023

I agree with @gendx's comment. Can you move black_box to be on the inputs only? (Then comment with at-rustbot ready to put it back in my queue).

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 2, 2023
@chenyukang
Copy link
Member Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 3, 2023
@thomcc
Copy link
Member

thomcc commented Feb 3, 2023

Looks good.

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Feb 3, 2023

📌 Commit fe84cec has been approved by thomcc

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 3, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 3, 2023
…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
@bors bors merged commit 8601551 into rust-lang:master Feb 3, 2023
@rustbot rustbot added this to the 1.69.0 milestone Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong benchmarks in library/core/benches/char/methods.rs and possibly other places
5 participants