diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-04-28 11:40:04 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-05-13 17:50:58 -0700 |
| commit | 556e76bb78cdd1d951e3966b2264ef8567371881 (patch) | |
| tree | 2b024aea65f5b77452414fd82a70150b956613c3 /src/libtest | |
| parent | 05d5fcaa5ba0c385e1dc97037c89fae437634fc3 (diff) | |
| download | rust-556e76bb78cdd1d951e3966b2264ef8567371881.tar.gz rust-556e76bb78cdd1d951e3966b2264ef8567371881.zip | |
std: Redesign Duration, implementing RFC 1040
This commit is an implementation of [RFC 1040][rfc] which is a redesign of the currently-unstable `Duration` type. The API of the type has been scaled back to be more conservative and it also no longer supports negative durations. [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1040-duration-reform.md The inner `duration` module of the `time` module has now been hidden (as `Duration` is reexported) and the feature name for this type has changed from `std_misc` to `duration`. All APIs accepting durations have also been audited to take a more flavorful feature name instead of `std_misc`. Closes #24874
Diffstat (limited to 'src/libtest')
| -rw-r--r-- | src/libtest/lib.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 9cbfe283cbd..649a0e57e60 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -43,6 +43,8 @@ #![feature(std_misc)] #![feature(libc)] #![feature(set_stdio)] +#![feature(duration)] +#![feature(duration_span)] extern crate getopts; extern crate serialize; @@ -1069,7 +1071,7 @@ impl Bencher { } pub fn ns_elapsed(&mut self) -> u64 { - self.dur.num_nanoseconds().unwrap() as u64 + self.dur.secs() * 1_000_000_000 + (self.dur.extra_nanos() as u64) } pub fn ns_per_iter(&mut self) -> u64 { @@ -1105,7 +1107,7 @@ impl Bencher { // (i.e. larger error bars). if n == 0 { n = 1; } - let mut total_run = Duration::nanoseconds(0); + let mut total_run = Duration::new(0, 0); let samples : &mut [f64] = &mut [0.0_f64; 50]; loop { let mut summ = None; @@ -1134,7 +1136,7 @@ impl Bencher { // If we've run for 100ms and seem to have converged to a // stable median. - if loop_run.num_milliseconds() > 100 && + if loop_run > Duration::from_millis(100) && summ.median_abs_dev_pct < 1.0 && summ.median - summ5.median < summ5.median_abs_dev { return summ5; @@ -1142,7 +1144,7 @@ impl Bencher { total_run = total_run + loop_run; // Longest we ever run for is 3s. - if total_run.num_seconds() > 3 { + if total_run > Duration::from_secs(3) { return summ5; } @@ -1166,7 +1168,7 @@ pub mod bench { pub fn benchmark<F>(f: F) -> BenchSamples where F: FnMut(&mut Bencher) { let mut bs = Bencher { iterations: 0, - dur: Duration::nanoseconds(0), + dur: Duration::new(0, 0), bytes: 0 }; @@ -1185,7 +1187,7 @@ pub mod bench { pub fn run_once<F>(f: F) where F: FnOnce(&mut Bencher) { let mut bs = Bencher { iterations: 0, - dur: Duration::nanoseconds(0), + dur: Duration::new(0, 0), bytes: 0 }; bs.bench_n(1, f); |
