1
- use core :: fmt :: Debug ;
1
+ #! [ feature ( duration_constants ) ]
2
2
3
- #[ cfg( not( target_arch = "wasm32" ) ) ]
4
- use test:: { Bencher , black_box} ;
5
-
6
- use super :: { Duration , Instant , SystemTime , UNIX_EPOCH } ;
3
+ use std:: fmt:: Debug ;
4
+ use std:: time:: { Duration , Instant , SystemTime , UNIX_EPOCH } ;
7
5
8
6
macro_rules! assert_almost_eq {
9
7
( $a: expr, $b: expr) => { {
@@ -29,10 +27,10 @@ fn instant_monotonic() {
29
27
30
28
#[ test]
31
29
#[ cfg( not( target_arch = "wasm32" ) ) ]
32
- fn instant_monotonic_concurrent ( ) -> crate :: thread:: Result < ( ) > {
30
+ fn instant_monotonic_concurrent ( ) -> std :: thread:: Result < ( ) > {
33
31
let threads: Vec < _ > = ( 0 ..8 )
34
32
. map ( |_| {
35
- crate :: thread:: spawn ( || {
33
+ std :: thread:: spawn ( || {
36
34
let mut old = Instant :: now ( ) ;
37
35
let count = if cfg ! ( miri) { 1_000 } else { 5_000_000 } ;
38
36
for _ in 0 ..count {
@@ -229,46 +227,3 @@ fn big_math() {
229
227
check ( instant. checked_add ( Duration :: from_secs ( 100 ) ) , Instant :: checked_sub) ;
230
228
check ( instant. checked_add ( Duration :: from_secs ( i64:: MAX as _ ) ) , Instant :: checked_sub) ;
231
229
}
232
-
233
- macro_rules! bench_instant_threaded {
234
- ( $bench_name: ident, $thread_count: expr) => {
235
- #[ bench]
236
- #[ cfg( not( target_arch = "wasm32" ) ) ]
237
- fn $bench_name( b: & mut Bencher ) -> crate :: thread:: Result <( ) > {
238
- use crate :: sync:: Arc ;
239
- use crate :: sync:: atomic:: { AtomicBool , Ordering } ;
240
-
241
- let running = Arc :: new( AtomicBool :: new( true ) ) ;
242
-
243
- let threads: Vec <_> = ( 0 ..$thread_count)
244
- . map( |_| {
245
- let flag = Arc :: clone( & running) ;
246
- crate :: thread:: spawn( move || {
247
- while flag. load( Ordering :: Relaxed ) {
248
- black_box( Instant :: now( ) ) ;
249
- }
250
- } )
251
- } )
252
- . collect( ) ;
253
-
254
- b. iter( || {
255
- let a = Instant :: now( ) ;
256
- let b = Instant :: now( ) ;
257
- assert!( b >= a) ;
258
- } ) ;
259
-
260
- running. store( false , Ordering :: Relaxed ) ;
261
-
262
- for t in threads {
263
- t. join( ) ?;
264
- }
265
- Ok ( ( ) )
266
- }
267
- } ;
268
- }
269
-
270
- bench_instant_threaded ! ( instant_contention_01_threads, 0 ) ;
271
- bench_instant_threaded ! ( instant_contention_02_threads, 1 ) ;
272
- bench_instant_threaded ! ( instant_contention_04_threads, 3 ) ;
273
- bench_instant_threaded ! ( instant_contention_08_threads, 7 ) ;
274
- bench_instant_threaded ! ( instant_contention_16_threads, 15 ) ;
0 commit comments