mybench

Crates.iomybench
lib.rsmybench
version0.1.8
created_at2020-05-22 07:06:00.216515+00
updated_at2020-06-04 03:51:14.546965+00
descriptionSimple (and very primitive) benchmarking macro.
homepagehttps://github.com/dvshapkin/mybench
repositoryhttps://github.com/dvshapkin/mybench
max_upload_size
id244455
size5,446
dvshapkin (dvshapkin)

documentation

https://docs.rs/mybench

README

mybench

Crates.io

Simple (and very primitive) benchmarking macro.

Use cases:

  • bench!(wrapper, "Prompt") calculates average execution time for code inside wrapper function for 10,000 times.

  • bench!(wrapper, number_of_repetitions, "Prompt") calculates average execution time for code inside wrapper function for number_of_repetitions times.

Result is displayed as filename:row:col 'Prompt' xxx.yy ms

Examples


#[macro_use]
extern crate mybench;

#[test]
fn bench_ok() {
    // with wrapper function
    bench!(wrapper, "Prompt 1");
    bench!(wrapper, 100_000, "Prompt 2");

    // or you may use closure
    bench!(|| {
        for i in 0..1000 {
            let _ = i*i;
        }
    }, 
    100_000, "With closure");
}

fn wrapper() {
    for i in 0..1000 {
        let _ = i*i;
    }
}

Output:


running 1 test
tests\mybench.rs:6:5 'Prompt 1' 29.581µs
tests\mybench.rs:7:5 'Prompt 2' 29.693µs
test bench_ok ... ok

If you don't see stdout, try this: cargo test -- --show-output

If you see:


test bench_ok ... test bench_ok has been running for over 60 seconds

Don't worry, this is an intermediate result (the test is not yet completed). Wait a little longer and let the test end.

Commit count: 0

cargo fmt