Skip to content

Commit

Permalink
#88 better testing
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Apr 27, 2023
1 parent 999df62 commit 56e4205
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions tests/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,31 @@ fn benchmark(total: usize) -> HashMap<&'static str, Duration> {
ret
}

/// Run it like this from the command line:
///
/// ```text
/// $ cargo test --release benchmark_and_print -- --nocapture
/// ```
#[test]
pub fn benchmark_and_print() {
let times = benchmark(100000);
let times = benchmark(
#[cfg(debug_assertions)]
100000,
#[cfg(not(debug_assertions))]
10000000,
);
let ours = times.get("micromap::Map").unwrap();
let mut total = 0.0;
for (m, d) in &times {
println!(
"{m} -> {:?} ({:.2}x)",
d,
d.as_nanos() as f64 / ours.as_nanos() as f64
);
let gain = d.as_nanos() as f64 / ours.as_nanos() as f64;
println!("{m} -> {:?} ({:.2}x)", d, gain);
if d == ours {
continue;
}
assert!(d.cmp(ours).is_gt());
total += gain;
}
println!("Total gain: {:.2}", total);
}

pub fn main() {
Expand Down

0 comments on commit 56e4205

Please sign in to comment.