mybench

Crates.io

Simple (and very primitive) benchmarking macro.

Use cases:

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

Examples


#[macro_use]
extern crate mybench;

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

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.