| Crates.io | mybench |
| lib.rs | mybench |
| version | 0.1.8 |
| created_at | 2020-05-22 07:06:00.216515+00 |
| updated_at | 2020-06-04 03:51:14.546965+00 |
| description | Simple (and very primitive) benchmarking macro. |
| homepage | https://github.com/dvshapkin/mybench |
| repository | https://github.com/dvshapkin/mybench |
| max_upload_size | |
| id | 244455 |
| size | 5,446 |
Simple (and very primitive) benchmarking macro.
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
#[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.