diff options
| author | bors <bors@rust-lang.org> | 2015-05-15 03:46:42 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-05-15 03:46:42 +0000 |
| commit | 0077ffe547a17ca05835c10a178bb9091e509820 (patch) | |
| tree | 816ce88e9a48c013c0234c2aa48411a4ae04b260 | |
| parent | daabc8a0c70693aaec3a424768ee216f59997acb (diff) | |
| parent | 140577b5aa63826ecfceb1230fbea12edf28b607 (diff) | |
| download | rust-0077ffe547a17ca05835c10a178bb9091e509820.tar.gz rust-0077ffe547a17ca05835c10a178bb9091e509820.zip | |
Auto merge of #25419 - nrc:time, r=alexcrichton
r? @alexcrichton
| -rw-r--r-- | src/librustc/util/common.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index 5a5567c48ad..8d5357fa6e4 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -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 |
