From a18680cb53d86a00f90e864a777a53c59d5cd294 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 15 Mar 2025 20:26:21 +0100 Subject: [PATCH] timer: use write! instead of intermediate format! See #10937 --- src/timer.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/timer.rs b/src/timer.rs index 7f74e9a11..f2ae453e1 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -14,6 +14,7 @@ //! but it's still the best we can do because we don't know how long of a time might elapse between //! `TimerSnapshot` instances and need to avoid rollover. +use std::fmt::Write as FmtWrite; use std::io::Write; use std::time::{Duration, Instant}; @@ -82,11 +83,12 @@ pub fn get_delta(t1: &TimerSnapshot, t2: &TimerSnapshot, verbose: bool) -> Strin let usr_time = cpu_unit.convert_micros(net_usr_micros); let mut output = String::new(); + #[rustfmt::skip] if !verbose { - output += "\n_______________________________"; - output += &format!("\nExecuted in {:6.2} {}", wall_time, wall_unit.long_name()); - output += &format!("\n usr time {:6.2} {}", usr_time, cpu_unit.long_name()); - output += &format!("\n sys time {:6.2} {}", sys_time, cpu_unit.long_name()); + write!(output, "\n_______________________________").unwrap(); + write!(output, "\nExecuted in {:6.2} {}", wall_time, wall_unit.long_name()).unwrap(); + write!(output, "\n usr time {:6.2} {}", usr_time, cpu_unit.long_name()).unwrap(); + write!(output, "\n sys time {:6.2} {}", sys_time, cpu_unit.long_name()).unwrap(); } else { let fish_unit = Unit::for_micros(fish_sys.max(fish_usr).as_micros() as i64); let child_unit = Unit::for_micros(child_sys.max(child_usr).as_micros() as i64); @@ -105,15 +107,17 @@ pub fn get_delta(t1: &TimerSnapshot, t2: &TimerSnapshot, verbose: bool) -> Strin let child_unit = child_unit.short_name(); output += "\n________________________________________________________"; - output += &format!( + write!( + output, "\nExecuted in {wall_time:6.2} {wall_unit: