34
34
35
35
#![ cfg_attr( feature = "asm_black_box" , feature( asm) ) ]
36
36
#![ feature( set_stdio) ]
37
- #![ feature( time2) ]
38
37
39
38
extern crate getopts;
40
39
extern crate rustc_serialize;
41
40
extern crate term;
42
41
extern crate libc;
42
+ extern crate time;
43
43
44
44
pub use self :: TestFn :: * ;
45
45
pub use self :: ColorConfig :: * ;
@@ -52,6 +52,7 @@ use self::OutputLocation::*;
52
52
use stats:: Stats ;
53
53
use rustc_serialize:: Encodable ;
54
54
use term:: Terminal ;
55
+ use time:: { PreciseTime , Duration } ;
55
56
56
57
use std:: any:: Any ;
57
58
use std:: cmp;
@@ -66,7 +67,6 @@ use std::path::PathBuf;
66
67
use std:: sync:: mpsc:: { channel, Sender } ;
67
68
use std:: sync:: { Arc , Mutex } ;
68
69
use std:: thread;
69
- use std:: time:: { Instant , Duration } ;
70
70
71
71
// to be used by rustc to compile tests in libtest
72
72
pub mod test {
@@ -1204,16 +1204,16 @@ impl Bencher {
1204
1204
pub fn iter < T , F > ( & mut self , mut inner : F )
1205
1205
where F : FnMut ( ) -> T
1206
1206
{
1207
- let start = Instant :: now ( ) ;
1207
+ let start = PreciseTime :: now ( ) ;
1208
1208
let k = self . iterations ;
1209
1209
for _ in 0 ..k {
1210
1210
black_box ( inner ( ) ) ;
1211
1211
}
1212
- self . dur = start. elapsed ( ) ;
1212
+ self . dur = start. to ( PreciseTime :: now ( ) ) ;
1213
1213
}
1214
1214
1215
1215
pub fn ns_elapsed ( & mut self ) -> u64 {
1216
- self . dur . as_secs ( ) * 1_000_000_000 + ( self . dur . subsec_nanos ( ) as u64 )
1216
+ self . dur . num_nanoseconds ( ) . unwrap ( ) as u64
1217
1217
}
1218
1218
1219
1219
pub fn ns_per_iter ( & mut self ) -> u64 {
@@ -1255,10 +1255,10 @@ impl Bencher {
1255
1255
n = 1 ;
1256
1256
}
1257
1257
1258
- let mut total_run = Duration :: new ( 0 , 0 ) ;
1258
+ let mut total_run = Duration :: seconds ( 0 ) ;
1259
1259
let samples: & mut [ f64 ] = & mut [ 0.0_f64 ; 50 ] ;
1260
1260
loop {
1261
- let loop_start = Instant :: now ( ) ;
1261
+ let loop_start = PreciseTime :: now ( ) ;
1262
1262
1263
1263
for p in & mut * samples {
1264
1264
self . bench_n ( n, |x| f ( x) ) ;
@@ -1275,18 +1275,18 @@ impl Bencher {
1275
1275
1276
1276
stats:: winsorize ( samples, 5.0 ) ;
1277
1277
let summ5 = stats:: Summary :: new ( samples) ;
1278
- let loop_run = loop_start. elapsed ( ) ;
1278
+ let loop_run = loop_start. to ( PreciseTime :: now ( ) ) ;
1279
1279
1280
1280
// If we've run for 100ms and seem to have converged to a
1281
1281
// stable median.
1282
- if loop_run > Duration :: from_millis ( 100 ) && summ. median_abs_dev_pct < 1.0 &&
1282
+ if loop_run > Duration :: milliseconds ( 100 ) && summ. median_abs_dev_pct < 1.0 &&
1283
1283
summ. median - summ5. median < summ5. median_abs_dev {
1284
1284
return summ5;
1285
1285
}
1286
1286
1287
1287
total_run = total_run + loop_run;
1288
1288
// Longest we ever run for is 3s.
1289
- if total_run > Duration :: from_secs ( 3 ) {
1289
+ if total_run > Duration :: seconds ( 3 ) {
1290
1290
return summ5;
1291
1291
}
1292
1292
@@ -1304,15 +1304,15 @@ impl Bencher {
1304
1304
1305
1305
pub mod bench {
1306
1306
use std:: cmp;
1307
- use std :: time:: Duration ;
1307
+ use time:: Duration ;
1308
1308
use super :: { Bencher , BenchSamples } ;
1309
1309
1310
1310
pub fn benchmark < F > ( f : F ) -> BenchSamples
1311
1311
where F : FnMut ( & mut Bencher )
1312
1312
{
1313
1313
let mut bs = Bencher {
1314
1314
iterations : 0 ,
1315
- dur : Duration :: new ( 0 , 0 ) ,
1315
+ dur : Duration :: seconds ( 0 ) ,
1316
1316
bytes : 0 ,
1317
1317
} ;
1318
1318
@@ -1332,7 +1332,7 @@ pub mod bench {
1332
1332
{
1333
1333
let mut bs = Bencher {
1334
1334
iterations : 0 ,
1335
- dur : Duration :: new ( 0 , 0 ) ,
1335
+ dur : Duration :: seconds ( 0 ) ,
1336
1336
bytes : 0 ,
1337
1337
} ;
1338
1338
bs. bench_n ( 1 , f) ;
0 commit comments