Skip to content

Commit c78ac29

Browse files
committed
Show millisecond precision for time_passes times
Closes #713
1 parent a11bb40 commit c78ac29

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/comp/driver/rustc.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,11 @@ fn parse_input(sess: session::session, cfg: &ast::crate_cfg, input: str) ->
9999

100100
fn time[T](do_it: bool, what: str, thunk: fn() -> T ) -> T {
101101
if !do_it { ret thunk(); }
102-
let start = std::time::get_time();
102+
let start = std::time::precise_time_s();
103103
let rv = thunk();
104-
let end = std::time::get_time();
105-
// FIXME: Actually do timeval math.
106-
107-
log_err #fmt("time: %s took %u s", what, end.sec - start.sec as uint);
104+
let end = std::time::precise_time_s();
105+
log_err #fmt("time: %s took %s s", what,
106+
common::float_to_str(end - start, 3u));
108107
ret rv;
109108
}
110109

src/comp/util/common.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,28 @@ fn call_kind_str(c: call_kind) -> str {
163163
fn is_main_name(path: &str[]) -> bool {
164164
str::eq(option::get(std::ivec::last(path)), "main")
165165
}
166+
167+
// FIXME mode this to std::float when editing the stdlib no longer
168+
// requires a snapshot
169+
fn float_to_str(num: float, digits: uint) -> str {
170+
let accum = if num < 0.0 { num = -num; "-" }
171+
else { "" };
172+
let trunc = num as uint;
173+
let frac = num - (trunc as float);
174+
accum += uint::str(trunc);
175+
if frac == 0.0 || digits == 0u { ret accum; }
176+
accum += ".";
177+
while digits > 0u && frac > 0.0 {
178+
frac *= 10.0;
179+
let digit = frac as uint;
180+
accum += uint::str(digit);
181+
frac -= digit as float;
182+
digits -= 1u;
183+
}
184+
ret accum;
185+
}
186+
187+
166188
//
167189
// Local Variables:
168190
// mode: rust

0 commit comments

Comments
 (0)