@@ -94,19 +94,20 @@ async fn kanal_async(c: usize, task_count: usize) {
9494 handles. push ( task:: spawn ( async move {
9595 for _ in 0 ..task_count {
9696 for _ in 0 ..1 {
97- let x: Message = rx. recv ( ) . await . unwrap ( ) ;
98- test_func ( x. item_one as u128 ) ;
97+ let x = rx. recv ( ) . await . unwrap ( ) ;
98+ // test_func(x as u128);
9999 }
100100 }
101101 } ) ) ;
102102 }
103103
104104 for _ in 0 ..task_count {
105105 let tx = s. clone ( ) ;
106- let msg = Message :: default ( ) ;
106+ // let msg = Message::default();
107107 handles. push ( task:: spawn ( async move {
108108 for i in 0 ..1 {
109- tx. send ( msg) . await . unwrap ( ) ;
109+ // tx.send(msg).await.unwrap();
110+ tx. send ( i) . await . unwrap ( ) ;
110111 }
111112 } ) ) ;
112113 }
@@ -125,10 +126,11 @@ async fn kanal_async_with_msg_vec(
125126 let ( s, r) = bounded_async ( c) ;
126127 let mut handles = Vec :: new ( ) ;
127128
128- for _ in 0 ..1 {
129+ // for _ in 0..1 {
130+ for _ in 0 ..8 {
129131 let rx = r. clone ( ) ;
130132 handles. push ( task:: spawn ( async move {
131- for _ in 0 ..task_count {
133+ for _ in 0 ..task_count/ 8 {
132134 for _ in 0 ..msg_count {
133135 let x = rx. recv ( ) . await . unwrap ( ) ;
134136 // test_func(x.item_one as u128);
@@ -156,20 +158,48 @@ async fn kanal_async_with_msg_vec(
156158fn benchmark_kanal_async ( c : & mut Criterion ) {
157159 const MAX_THREADS : [ usize ; 1 ] = [ 8 ] ;
158160 const CAPACITY : usize = 128 ;
159- const TASKS : [ usize ; 1 ] = [ 100000 ] ;
160- const MSG_COUNT : usize = 1 ;
161- let msg = BigData {
162- buf : Box :: new ( [ 0 ; 8 ] ) ,
163- } ;
164- let mut msg_vecs = Vec :: with_capacity ( TASKS [ 0 ] ) ;
165- for _ in 0 ..TASKS [ 0 ] {
166- msg_vecs. push ( Vec :: with_capacity ( MSG_COUNT ) ) ;
167- let msg_vecs_len = msg_vecs. len ( ) ;
168- for _ in 0 ..MSG_COUNT {
169- msg_vecs[ msg_vecs_len - 1 ] . push ( msg. clone ( ) ) ;
161+ const TASKS : [ usize ; 1 ] = [ 100 ] ;
162+
163+ for thread_num in MAX_THREADS {
164+ let runtime = tokio:: runtime:: Builder :: new_multi_thread ( )
165+ . enable_all ( )
166+ . worker_threads ( thread_num)
167+ . build ( )
168+ . unwrap ( ) ;
169+
170+ for task_count in TASKS {
171+ let func_name = format ! (
172+ "Kanal Async: {} threads, {} enq tasks enqueuing 1 million items, 1 looping deq task" ,
173+ thread_num, task_count
174+ ) ;
175+
176+ c. bench_with_input (
177+ BenchmarkId :: new ( func_name, CAPACITY ) ,
178+ & ( CAPACITY ) ,
179+ |b, & cap| {
180+ // Insert a call to `to_async` to convert the bencher to async mode.
181+ // The timing loops are the same as with the normal bencher.
182+ b. to_async ( & runtime) . iter ( async || {
183+ kanal_async ( cap, task_count) . await ;
184+ } ) ;
185+ } ,
186+ ) ;
170187 }
171188 }
172189
190+ // const MSG_COUNT: usize = 1;
191+ // let msg = BigData {
192+ // buf: Box::new([0; 8]),
193+ // };
194+ // let mut msg_vecs = Vec::with_capacity(TASKS[0]);
195+ // for _ in 0..TASKS[0] {
196+ // msg_vecs.push(Vec::with_capacity(MSG_COUNT));
197+ // let msg_vecs_len = msg_vecs.len();
198+ // for _ in 0..MSG_COUNT {
199+ // msg_vecs[msg_vecs_len - 1].push(msg.clone());
200+ // }
201+ // }
202+
173203 // for thread_num in MAX_THREADS {
174204 // let runtime = tokio::runtime::Builder::new_multi_thread()
175205 // .enable_all()
@@ -179,8 +209,7 @@ fn benchmark_kanal_async(c: &mut Criterion) {
179209
180210 // for task_count in TASKS {
181211 // let func_name = format!(
182- // "Kanal Async: {} threads, {} enq tasks enqueuing 1 million items, 1 looping deq task",
183- // thread_num, task_count
212+ // "Kanal Async: {thread_num} threads, {task_count} enq tasks enqueuing 1 million items, 1 looping deq task"
184213 // );
185214
186215 // c.bench_with_input(
@@ -189,51 +218,25 @@ fn benchmark_kanal_async(c: &mut Criterion) {
189218 // |b, &cap| {
190219 // // Insert a call to `to_async` to convert the bencher to async mode.
191220 // // The timing loops are the same as with the normal bencher.
192- // b.to_async(&runtime).iter(async || {
193- // kanal_async(cap, task_count).await;
221+ // b.to_async(&runtime).iter_custom(|iters| {
222+ // let msg_vecs = msg_vecs.clone();
223+ // async move {
224+ // let mut total = Duration::ZERO;
225+ // for _ in 0..iters {
226+ // let msg_vecs = msg_vecs.clone();
227+ // let start = Instant::now();
228+ // kanal_async_with_msg_vec(msg_vecs, cap, task_count, MSG_COUNT)
229+ // .await;
230+ // let end = Instant::now();
231+ // total += end - start;
232+ // }
233+ // total
234+ // }
194235 // });
195236 // },
196237 // );
197238 // }
198239 // }
199-
200- for thread_num in MAX_THREADS {
201- let runtime = tokio:: runtime:: Builder :: new_multi_thread ( )
202- . enable_all ( )
203- . worker_threads ( thread_num)
204- . build ( )
205- . unwrap ( ) ;
206-
207- for task_count in TASKS {
208- let func_name = format ! (
209- "Kanal Async: {thread_num} threads, {task_count} enq tasks enqueuing 1 million items, 1 looping deq task"
210- ) ;
211-
212- c. bench_with_input (
213- BenchmarkId :: new ( func_name, CAPACITY ) ,
214- & ( CAPACITY ) ,
215- |b, & cap| {
216- // Insert a call to `to_async` to convert the bencher to async mode.
217- // The timing loops are the same as with the normal bencher.
218- b. to_async ( & runtime) . iter_custom ( |iters| {
219- let msg_vecs = msg_vecs. clone ( ) ;
220- async move {
221- let mut total = Duration :: ZERO ;
222- for _ in 0 ..iters {
223- let msg_vecs = msg_vecs. clone ( ) ;
224- let start = Instant :: now ( ) ;
225- kanal_async_with_msg_vec ( msg_vecs, cap, task_count, MSG_COUNT )
226- . await ;
227- let end = Instant :: now ( ) ;
228- total += end - start;
229- }
230- total
231- }
232- } ) ;
233- } ,
234- ) ;
235- }
236- }
237240}
238241
239242criterion_group ! ( benches, benchmark_kanal_async) ;
0 commit comments