Skip to content

Run benchmarks once, as a test by default. #25048

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

Merged
merged 1 commit into from
May 3, 2015
Merged

Conversation

huonw
Copy link
Member

@huonw huonw commented 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 #15842.

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.
@rust-highfive
Copy link
Contributor

r? @alexcrichton

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

@huonw
Copy link
Member Author

huonw commented May 2, 2015

Oh, there's an "obvious" alternative: have this behaviour be opt-in, --test-benches or something.

@alexcrichton
Copy link
Member

@bors: r+ d73545c

Nice idea!

bors added a commit that referenced this pull request 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
Copy link
Collaborator

bors commented May 3, 2015

⌛ Testing commit d73545c with merge 26933a6...

@bors
Copy link
Collaborator

bors commented May 3, 2015

@bors bors merged commit d73545c into rust-lang:master May 3, 2015
@huonw huonw deleted the test-benches branch May 5, 2015 03:23
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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