diff --git a/src/main.rs b/src/main.rs index 8b73862..706d6f6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -121,13 +121,33 @@ async fn main() { day.solve(part); let end = Instant::now(); timings.push(end - start); - if i % (n / 100) == 0 { - print!("\r{}%", ((i as f32 / n as f32) * 100.0).round()); - let _ = std::io::stdout().flush(); - } + + print!("\r{:.2}%", (i as f32 / n as f32) * 100.0); + let _ = std::io::stdout().flush(); } - let avg = timings.into_iter().sum::() / n; - println!("\nAverage timing: {}µs", avg.as_nanos() as f64 / 1000.0); + let avg = (timings.iter().sum::() / n).as_nanos(); + let deviation = (avg - timings.iter().min().unwrap().as_nanos()).max(timings.iter().max().unwrap().as_nanos() - avg); + + let (avg, avg_units) = if avg >= 1000000000 { + (avg as f64 / 1000000000.0, "s") + } else if avg >= 1000000 { + (avg as f64 / 1000000.0, "ms") + } else if avg >= 1000 { + (avg as f64 / 1000.0, "µs") + } else { + (avg as f64, "ns") + }; + + let (deviation, deviation_units) = if deviation >= 1000000000 { + (deviation as f64 / 1000000000.0, "s") + } else if deviation >= 1000000 { + (deviation as f64 / 1000000.0, "ms") + } else if deviation >= 1000 { + (deviation as f64 / 1000.0, "µs") + } else { + (deviation as f64, "ns") + }; + println!("\nAverage timing: {avg}{avg_units} ± {deviation}{deviation_units}"); } Subcommands::Input { day } => { let response = client