Skip to content

stdlib #[bench]s are (possibly) never run #15842

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
huonw opened this issue Jul 21, 2014 · 2 comments · Fixed by #25048
Closed

stdlib #[bench]s are (possibly) never run #15842

huonw opened this issue Jul 21, 2014 · 2 comments · Fixed by #25048
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc

Comments

@huonw
Copy link
Member

huonw commented Jul 21, 2014

It seems to me that the only way for #15833 to be an issue is if we never run #[bench]s anywhere during a PR merge (or on travis etc.).

Maybe the test harness could run #[bench]s as normal tests during a normal run (i.e. execute the code exactly once, not bothering to time it).

@huonw huonw changed the title stdlib #[bench]s are (possibly) never compiled stdlib #[bench]s are (possibly) never run Jul 21, 2014
@alexcrichton
Copy link
Member

I believe they are all currently compiled, but never run unless you pass --bench which is quite rare.

Running a benchmark for one iteration seems quite reasonable!

@steveklabnik
Copy link
Member

Triage: don't think anything has changed here.

huonw added a commit to huonw/rust that referenced this issue May 2, 2015
E.g. if `foo.rs` looks like

    #![feature(test)]
    extern crate test;

    #[bench]
    fn bar(b: &mut test::Bencher) {
        b.iter(|| {
            1
        })
    }

    #[test]
    fn baz() {}

    #[bench]
    fn qux(b: &mut test::Bencher) {
        b.iter(|| {
            panic!()
        })
    }

Then

    $ rustc --test foo.rs
    $ ./foo

    running 3 tests
    test baz ... ok
    test qux ... FAILED
    test bar ... ok

    failures:

    ---- qux stdout ----
    	thread 'qux' panicked at 'explicit panic', bench.rs:17

    failures:
        qux

    test result: FAILED. 2 passed; 1 failed; 0 ignored; 0 measured

    $ ./foo --bench ba

    running 2 tests
    test baz ... ignored
    test bar ... bench:        97 ns/iter (+/- 74)

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

In particular, the two benchmark are being run as tests in the default
mode.

This helps for the main distribution, since benchmarks are only run with
`PLEASE_BENCH=1`, which is rarely set (and never set on the test bots),
and helps for code-coverage tools: benchmarks are run and so don't count
as dead code.

Fixes rust-lang#15842.
bors added a commit that referenced this issue May 3, 2015
E.g. if `foo.rs` looks like

    #![feature(test)]
    extern crate test;

    #[bench]
    fn bar(b: &mut test::Bencher) {
        b.iter(|| {
            1
        })
    }

    #[test]
    fn baz() {}

    #[bench]
    fn qux(b: &mut test::Bencher) {
        b.iter(|| {
            panic!()
        })
    }

Then

    $ rustc --test foo.rs
    $ ./foo

    running 3 tests
    test baz ... ok
    test qux ... FAILED
    test bar ... ok

    failures:

    ---- qux stdout ----
    	thread 'qux' panicked at 'explicit panic', bench.rs:17

    failures:
        qux

    test result: FAILED. 2 passed; 1 failed; 0 ignored; 0 measured

    $ ./foo --bench ba

    running 2 tests
    test baz ... ignored
    test bar ... bench:        97 ns/iter (+/- 74)

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

In particular, the two benchmark are being run as tests in the default
mode.

This helps for the main distribution, since benchmarks are only run with
`PLEASE_BENCH=1`, which is rarely set (and never set on the test bots),
and helps for code-coverage tools: benchmarks are run and so don't count
as dead code.

Fixes #15842.
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 8, 2024
fix: try obligation of `IndexMut` when infer

Closes rust-lang#15842.

This issue arises because `K` is ambiguous if only inferred from `Index` trait, but is unique if inferred from `IndexMut`, but r-a doesn't use this info.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants