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

Benchmark times should not display all significant figures. #10953

Closed
huonw opened this issue Dec 13, 2013 · 2 comments
Closed

Benchmark times should not display all significant figures. #10953

huonw opened this issue Dec 13, 2013 · 2 comments

Comments

@huonw
Copy link
Member

huonw commented Dec 13, 2013

#[feature(macro_rules, asm)];

extern mod extra;
use BH = extra::test::BenchHarness;
macro_rules! mk_benches(
    ( $($name:ident, $n:expr;)* ) => {

        $(
            #[bench]
            fn $name(bh: &mut BH) {
                bh.iter(|| for _ in range(0, $n) { unsafe {asm!("")}; } );
            }
            )*
    })

mk_benches! {
    a,           1;
    b,          40; // to get a meaningful time
    c,         100;
    d,       1_000;
    e,      10_000;
    f,     100_000;
    g,   1_000_000;
    h,  10_000_000;
    i, 100_000_000;
}

Compiled with rustc -O --test (using a rustc with #10952) shows

running 9 tests
test a ... bench:         2 ns/iter (+/- 1)
test b ... bench:        34 ns/iter (+/- 3)
test c ... bench:        62 ns/iter (+/- 8)
test d ... bench:       383 ns/iter (+/- 60)
test e ... bench:      3608 ns/iter (+/- 367)
test f ... bench:     35984 ns/iter (+/- 4093)
test g ... bench:    361734 ns/iter (+/- 98714)
test h ... bench:   3381412 ns/iter (+/- 281941)
test i ... bench:  34584793 ns/iter (+/- 2991062)

The long numbers are hard to read, and most of the digits are unnecessary. It would be clearer if we only showed a fixed precision, e.g., using engineering notation:

running 9 tests
test a ... bench:         2 ns/iter (+/-     1)
test b ... bench:        34 ns/iter (+/-     3)
test c ... bench:        62 ns/iter (+/-     8)
test d ... bench:       383 ns/iter (+/-    60)
test e ... bench:     3.6e3 ns/iter (+/-   367)
test f ... bench:    36.0e3 ns/iter (+/- 4.1e3)
test g ... bench:   361.7e3 ns/iter (+/-  99e3)
test h ... bench:     3.4e6 ns/iter (+/- 280e3)
test i ... bench:    34.6e6 ns/iter (+/- 3.0e6)

This specific notation has the advantages of easy local comparison, that is, tests that take approximately the same amount of time can easily be compared without accidentally missing 8.0e3 vs 1.0e4 (8e3 vs 10e3 under the proposed scheme).

This could also be achieved by changing the units (i.e. ns -> us -> ms), but I personally think that that difference is more subtle than necessary, but I don't have a particularly strong opinion on it.

running 9 tests
test a ... bench:         2 ns/iter (+/-    1)
test b ... bench:        34 ns/iter (+/-    3)
test c ... bench:        62 ns/iter (+/-    8)
test d ... bench:       383 ns/iter (+/-   60)
test e ... bench:       3.6 us/iter (+/- 0.37)
test f ... bench:      36.0 us/iter (+/-  4.1)
test g ... bench:     361.7 us/iter (+/-   99)
test h ... bench:       3.4 ms/iter (+/- 0.28)
test i ... bench:      34.6 ms/iter (+/-  3.0)
@steveklabnik
Copy link
Member

This is still an issue, but here's a new version of the example that compiles:

#![feature(macro_rules, asm)]

extern crate test;

use BH = test::Bencher;
macro_rules! mk_benches(
    ( $($name:ident, $n:expr;)* ) => {

        $(
            #[bench]
            fn $name(bh: &mut BH) {
                bh.iter(|| for _ in range(0i, $n) { unsafe {asm!("")}; } );
            }
            )*
    })

mk_benches! {
    a,           1;
    b,          40; // to get a meaningful time
    c,         100;
    d,       1_000;
    e,      10_000;
    f,     100_000;
    g,   1_000_000;
    h,  10_000_000;
    i, 100_000_000;
}

@bluss
Copy link
Member

bluss commented Jun 7, 2015

Testcase update once more to current rust nightly

#![feature(test)]

extern crate test;

use test::Bencher as BH;
macro_rules! mk_benches {
    ( $($name:ident, $n:expr;)* ) => {

        $(
            #[bench]
            fn $name(bh: &mut BH) {
                bh.iter(|| for _ in 0u64..$n { test::black_box(1); } );
            }
            )*
    }
}

mk_benches! {
    a,           1;
    b,          40; // to get a meaningful time
    c,         100;
    d,       1_000;
    e,      10_000;
    f,     100_000;
    g,   1_000_000;
    h,  10_000_000;
    i, 100_000_000;
}

bluss pushed a commit to bluss/rust that referenced this issue Jun 9, 2015
Example display:

```
running 9 tests
test a ... bench:           0 ns/iter (+/- 0)
test b ... bench:          52 ns/iter (+/- 0)
test c ... bench:          88 ns/iter (+/- 0)
test d ... bench:         618 ns/iter (+/- 111)
test e ... bench:       5,933 ns/iter (+/- 87)
test f ... bench:      59,280 ns/iter (+/- 1,052)
test g ... bench:     588,672 ns/iter (+/- 3,381)
test h ... bench:   5,894,227 ns/iter (+/- 303,489)
test i ... bench:  59,112,382 ns/iter (+/- 1,500,110)
```

Fixes rust-lang#10953
Fixes rust-lang#26109
bors added a commit that referenced this issue Jun 9, 2015
test: Display benchmark results with thousands separators

Example display:

```
running 9 tests
test a ... bench:           0 ns/iter (+/- 0)
test b ... bench:          52 ns/iter (+/- 0)
test c ... bench:          88 ns/iter (+/- 0)
test d ... bench:         618 ns/iter (+/- 111)
test e ... bench:       5,933 ns/iter (+/- 87)
test f ... bench:      59,280 ns/iter (+/- 1,052)
test g ... bench:     588,672 ns/iter (+/- 3,381)
test h ... bench:   5,894,227 ns/iter (+/- 303,489)
test i ... bench:  59,112,382 ns/iter (+/- 1,500,110)
```

Fixes #10953
Fixes #26109
flip1995 pushed a commit to flip1995/rust that referenced this issue Jun 30, 2023
…trigger_on_expect, r=dswij

[`missing_panics_doc`]: pickup expect method

close rust-lang#10240

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: [`missing_panics_doc`]: pickup expect method
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

3 participants