canic_utils/instructions.rs
1//!
2//! Helpers for formatting raw instruction counts into friendly strings.
3//!
4
5///
6/// Format an instruction count using engineering suffixes (K/M/B/T).
7///
8#[must_use]
9#[allow(clippy::cast_precision_loss)]
10pub fn format_instructions(n: u64) -> String {
11 if n >= 1_000_000_000_000 {
12 format!("{:.2}T", n as f64 / 1_000_000_000_000.0)
13 } else if n >= 1_000_000_000 {
14 format!("{:.2}B", n as f64 / 1_000_000_000.0)
15 } else if n >= 1_000_000 {
16 format!("{:.2}M", n as f64 / 1_000_000.0)
17 } else if n >= 1_000 {
18 format!("{:.2}K", n as f64 / 1_000.0)
19 } else {
20 format!("{n}")
21 }
22}