Fix printing of fractional millisecond timestamps. (#582) r=emily

This commit is contained in:
Richard Newman 2018-03-05 18:02:34 -08:00
parent 1817ce7c0b
commit 3e615becd8

View file

@ -126,29 +126,30 @@ fn format_time(duration: Duration) {
let m_micros = duration.num_microseconds(); let m_micros = duration.num_microseconds();
if let Some(micros) = m_micros { if let Some(micros) = m_micros {
if micros < 10_000 { if micros < 1_000 {
let ns = m_nanos.unwrap_or(0) / 1000; eprintln!("{bold}{micros}{reset}µs",
eprintln!("{bold}{micros}.{ns}{reset}µs",
bold = style::Bold, bold = style::Bold,
micros = micros, micros = micros,
ns = ns,
reset = style::Reset); reset = style::Reset);
return; return;
} }
if micros < 1_000_000 {
// Print as millis.
let millis = (micros as f64) / 1000f64;
eprintln!("{bold}{millis}{reset}ms",
bold = style::Bold,
millis = millis,
reset = style::Reset);
return;
}
} }
let millis = duration.num_milliseconds(); let millis = duration.num_milliseconds();
if millis < 5_000 { let seconds = (millis as f64) / 1000f64;
eprintln!("{bold}{millis}.{micros}{reset}ms", eprintln!("{bold}{seconds}{reset}s",
bold = style::Bold,
millis = millis,
micros = m_micros.unwrap_or(0) / 1000,
reset = style::Reset);
return;
}
eprintln!("{bold}{seconds}.{millis}{reset}s",
bold = style::Bold, bold = style::Bold,
seconds = duration.num_seconds(), seconds = seconds,
millis = millis,
reset = style::Reset); reset = style::Reset);
} }