From: Ummon Date: Fri, 6 Dec 2019 21:00:08 +0000 (+0100) Subject: Better display of measured time X-Git-Url: https://git.euphorik.ch/?a=commitdiff_plain;h=40bcf2ecd1afa4fb8050ab660b7318528038f900;p=advent_of_code_2019.git Better display of measured time --- diff --git a/src/main.rs b/src/main.rs index b508728..56fefeb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,9 +27,19 @@ fn day03() -> String { ) } +fn format_micros(t: u128) -> String { + if t < 10_000 { + format!("{} μs", t) + } else if t < 10_000_000u128 { + format!("{} ms", t / 1_000u128) + } else { + format!("{} s", t / 1_000_000u128) + } +} + fn do_day(days: &[fn() -> String], day: usize) { let now = Instant::now(); - println!("Result of day {}: {} (time: {} μs)", day, days[day - 1](), now.elapsed().as_micros()); + println!("Result of day {}: {} (time: {})", day, days[day - 1](), format_micros(now.elapsed().as_micros())); } fn main() {