@@ -7,6 +7,9 @@ fn ticked_async_executor_benchmark(c: &mut Criterion) {
77
88 #[ cfg( feature = "tick_event" ) ]
99 timer_from_tick_event_benchmark ( c) ;
10+
11+ #[ cfg( feature = "timer_registration" ) ]
12+ timer_from_timer_registration_benchmark ( c) ;
1013}
1114
1215fn spawn_tasks_benchmark ( c : & mut Criterion ) {
@@ -72,8 +75,8 @@ fn timer_from_tick_event_benchmark(c: &mut Criterion) {
7275 c. bench_function ( "Spawn 1 timer from tick event" , |b| {
7376 b. iter_with_large_drop ( || {
7477 let mut executor = TickedAsyncExecutor :: default ( ) ;
75- let timer = executor. create_timer_from_tick_event ( ) ;
7678
79+ let timer = executor. create_timer_from_tick_event ( ) ;
7780 executor
7881 . spawn_local ( "empty" , async move {
7982 timer. sleep_for ( 1.0 ) . await ;
@@ -98,9 +101,44 @@ fn timer_from_tick_event_benchmark(c: &mut Criterion) {
98101 . detach ( ) ;
99102 }
100103
101- for _ in 0 ..11 {
102- executor. tick ( 0.1 , None ) ;
104+ executor. wait_till_completed ( 0.1 ) ;
105+ assert_eq ! ( executor. num_tasks( ) , 0 ) ;
106+ } ) ;
107+ } ) ;
108+ }
109+
110+ #[ cfg( feature = "timer_registration" ) ]
111+ fn timer_from_timer_registration_benchmark ( c : & mut Criterion ) {
112+ c. bench_function ( "Spawn 1 timer from timer registration" , |b| {
113+ b. iter_with_large_drop ( || {
114+ let mut executor = TickedAsyncExecutor :: default ( ) ;
115+
116+ let timer = executor. create_timer_from_timer_registration ( ) ;
117+ executor
118+ . spawn_local ( "empty" , async move {
119+ timer. sleep_for ( 1.0 ) . await ;
120+ } )
121+ . detach ( ) ;
122+
123+ executor. wait_till_completed ( 0.1 ) ;
124+ assert_eq ! ( executor. num_tasks( ) , 0 ) ;
125+ } ) ;
126+ } ) ;
127+
128+ c. bench_function ( "Spawn 1000 timers from timer registration" , |b| {
129+ b. iter_with_large_drop ( || {
130+ let mut executor = TickedAsyncExecutor :: default ( ) ;
131+
132+ for _ in 0 ..1000 {
133+ let timer = executor. create_timer_from_timer_registration ( ) ;
134+ executor
135+ . spawn_local ( "empty" , async move {
136+ timer. sleep_for ( 1.0 ) . await ;
137+ } )
138+ . detach ( ) ;
103139 }
140+
141+ executor. wait_till_completed ( 0.1 ) ;
104142 assert_eq ! ( executor. num_tasks( ) , 0 ) ;
105143 } ) ;
106144 } ) ;
0 commit comments