Skip to content

Commit

Permalink
Don't use <Duration as Display>::display() in time passes
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed May 14, 2015
1 parent dd4dad8 commit 140577b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/librustc/util/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,24 @@ pub fn time<T, U, F>(do_it: bool, what: &str, u: U, f: F) -> T where
r
});

let mut u = Some(u);
let mut rv = None;
let dur = {
let ref mut rvp = rv;

Duration::span(move || {
*rvp = Some(f(u.take().unwrap()))
*rvp = Some(f(u))
})
};
let rv = rv.unwrap();

println!("{}time: {} \t{}", repeat(" ").take(old).collect::<String>(),
dur, what);
// Hack up our own formatting for the duration to make it easier for scripts
// to parse (always use the same number of decimal places and the same unit).
const NANOS_PER_SEC: f64 = 1_000_000_000.0;
let secs = dur.secs() as f64;
let secs = secs + dur.extra_nanos() as f64 / NANOS_PER_SEC;
println!("{}time: {:.3} \t{}", repeat(" ").take(old).collect::<String>(),
secs, what);

DEPTH.with(|slot| slot.set(old));

rv
Expand Down

0 comments on commit 140577b

Please sign in to comment.