1- use core :: fmt :: Debug ;
1+ #! [ feature ( duration_constants ) ]
22
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 } ;
75
86macro_rules! assert_almost_eq {
97 ( $a: expr, $b: expr) => { {
@@ -29,10 +27,10 @@ fn instant_monotonic() {
2927
3028#[ test]
3129#[ cfg( not( target_arch = "wasm32" ) ) ]
32- fn instant_monotonic_concurrent ( ) -> crate :: thread:: Result < ( ) > {
30+ fn instant_monotonic_concurrent ( ) -> std :: thread:: Result < ( ) > {
3331 let threads: Vec < _ > = ( 0 ..8 )
3432 . map ( |_| {
35- crate :: thread:: spawn ( || {
33+ std :: thread:: spawn ( || {
3634 let mut old = Instant :: now ( ) ;
3735 let count = if cfg ! ( miri) { 1_000 } else { 5_000_000 } ;
3836 for _ in 0 ..count {
@@ -229,46 +227,3 @@ fn big_math() {
229227 check ( instant. checked_add ( Duration :: from_secs ( 100 ) ) , Instant :: checked_sub) ;
230228 check ( instant. checked_add ( Duration :: from_secs ( i64:: MAX as _ ) ) , Instant :: checked_sub) ;
231229}
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