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

--test -Z lto optimizes the benchmarks out #11902

Closed
ghost opened this issue Jan 29, 2014 · 1 comment
Closed

--test -Z lto optimizes the benchmarks out #11902

ghost opened this issue Jan 29, 2014 · 1 comment

Comments

@ghost
Copy link

ghost commented Jan 29, 2014

Without LTO:

running 4 tests
test xxhash::rust::test ... ok
test xxhash::native::test ... ok
test xxhash::native::bench ... bench:     75535 ns/iter (+/- 564) = 3470 MB/s
test xxhash::rust::bench   ... bench:     68471 ns/iter (+/- 953) = 3828 MB/s

test result: ok. 2 passed; 0 failed; 0 ignored; 2 measured

With LTO:

running 4 tests
test xxhash::rust::test ... ok
test xxhash::native::test ... ok
test xxhash::native::bench ... bench:     75598 ns/iter (+/- 109) = 3467 MB/s
test xxhash::rust::bench   ... bench:         0 ns/iter (+/- 0) = 262144000 MB/s

test result: ok. 2 passed; 0 failed; 0 ignored; 2 measured
@huonw
Copy link
Member

huonw commented Jan 29, 2014

This is a fundamental problem of micro-benchmarks with an optimising compiler: it can and will change code in unexpected ways (including removing code that it sees as dead, i.e. results that are not used where the computation is has no external effects).

One way around this is to trick the compiler into thinking that a result is used. E.g. for a sufficiently compilcated computation (so the optimiser cannot constant-fold it):

bh.iter(|| {
    let result = /* calculation */;
    if result == 0 { println!("no dead code elimination"); }
})

(works best if result is never zero, or choosing some other value to compare against.)

Even the stdlib has many instances of benchmarks that have their contents removed with optimisations on.

I would think that the change that LTO introduces is (a) just giving LLVM more passes with which to reduce and eliminate code, and (b) allowing the benchmarking harness (specifically the .iter function) itself to be inlined. (Compiling with --opt-level=3 may show a similar elimination of dead code.)

In any case, I believe this is a dupe of #8261.

@huonw huonw closed this as completed Jan 29, 2014
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 25, 2022
…icola

Increase defalt chalk overflow depth to match max solver size

TBC:

 - rust-lang#12279: ok above 480
 - ~~rust-lang#12182~~
 - ~~rust-lang#12095~~
 - rust-lang#11902: ok above 350
 - ~~rust-lang#11668~~
 - rust-lang#11370: ok above 450
 - rust-lang#9754: probably ok above 250 (!), and the code in cause and branch are gone

Closes rust-lang#12279
Closes rust-lang#11902
Closes rust-lang#11370
Closes rust-lang#9754
flip1995 pushed a commit to flip1995/rust that referenced this issue Dec 16, 2023
…ogiq

Add `ineffective_open_options` lint

Fixes rust-lang/rust-clippy#9628.

For `OpenOptions`, in case you call both `write(true)` and `append(true)` on `OpenOptions`, then `write(true)` is actually useless since `append(true)` does it.

r? `@flip1995`

changelog: Add `ineffective_open_options` lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant