Show millisecond precision for time_passes times

Closes #713
This commit is contained in:
Marijn Haverbeke 2011-07-22 12:03:10 +02:00
parent a11bb404a5
commit c78ac29002
2 changed files with 26 additions and 5 deletions

View file

@ -99,12 +99,11 @@ fn parse_input(sess: session::session, cfg: &ast::crate_cfg, input: str) ->
fn time[T](do_it: bool, what: str, thunk: fn() -> T ) -> T {
if !do_it { ret thunk(); }
let start = std::time::get_time();
let start = std::time::precise_time_s();
let rv = thunk();
let end = std::time::get_time();
// FIXME: Actually do timeval math.
log_err #fmt("time: %s took %u s", what, end.sec - start.sec as uint);
let end = std::time::precise_time_s();
log_err #fmt("time: %s took %s s", what,
common::float_to_str(end - start, 3u));
ret rv;
}

View file

@ -163,6 +163,28 @@ fn call_kind_str(c: call_kind) -> str {
fn is_main_name(path: &str[]) -> bool {
str::eq(option::get(std::ivec::last(path)), "main")
}
// FIXME mode this to std::float when editing the stdlib no longer
// requires a snapshot
fn float_to_str(num: float, digits: uint) -> str {
let accum = if num < 0.0 { num = -num; "-" }
else { "" };
let trunc = num as uint;
let frac = num - (trunc as float);
accum += uint::str(trunc);
if frac == 0.0 || digits == 0u { ret accum; }
accum += ".";
while digits > 0u && frac > 0.0 {
frac *= 10.0;
let digit = frac as uint;
accum += uint::str(digit);
frac -= digit as float;
digits -= 1u;
}
ret accum;
}
//
// Local Variables:
// mode: rust