( out: &mut impl fmt::Write, label: &str, hits: &AtomicU64, misses: &AtomicU64, )
| 351 | } |
| 352 | |
| 353 | fn write_rate( |
| 354 | out: &mut impl fmt::Write, |
| 355 | label: &str, |
| 356 | hits: &AtomicU64, |
| 357 | misses: &AtomicU64, |
| 358 | ) -> fmt::Result { |
| 359 | let h = hits.load(Ordering::Relaxed); |
| 360 | let m = misses.load(Ordering::Relaxed); |
| 361 | let total = h + m; |
| 362 | if total == 0 { |
| 363 | return writeln!(out, "{label} (no probes)"); |
| 364 | } |
| 365 | // 1-decimal rate is plenty for human reading. |
| 366 | #[allow(clippy::cast_precision_loss)] |
| 367 | let rate = (h as f64) / (total as f64) * 100.0; |
| 368 | writeln!(out, "{label} {h:>10} hits / {total:>10} total ({rate:>5.1}%)") |
| 369 | } |
| 370 | |
| 371 | #[cfg(test)] |
| 372 | mod tests { |
no outgoing calls