batch-channel 0.4.8

async channel that reduces overhead by reading and writing many values at once
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
use clap::Parser;
use clap::Subcommand;
use futures::future::BoxFuture;
use futures::FutureExt;
use itertools::Itertools;
use lazy_static::lazy_static;
use std::future::Future;
use std::time::Duration;
use std::time::Instant;

trait Channel {
    type Sender<T: Send + 'static>: ChannelSender<T> + 'static;
    type Receiver<T: Send + 'static>: ChannelReceiver<T> + 'static;

    fn bounded<T: Send + 'static>(capacity: usize) -> (Self::Sender<T>, Self::Receiver<T>);
}

trait ChannelSync {
    type SyncSender<T: Send + 'static>: ChannelSyncSender<T> + 'static;
    type SyncReceiver<T: Send + 'static>: ChannelSyncReceiver<T> + 'static;

    fn bounded_sync<T: Send + 'static>(
        capacity: usize,
    ) -> (Self::SyncSender<T>, Self::SyncReceiver<T>);
}

trait ChannelSender<T>: Clone + Send {
    type BatchSender: ChannelBatchSender<T>;

    fn autobatch<F>(self, batch_limit: usize, f: F) -> impl Future<Output = ()> + Send
    where
        for<'a> F: (FnOnce(&'a mut Self::BatchSender) -> BoxFuture<'a, ()>) + Send + 'static;
}

trait ChannelBatchSender<T>: Send {
    fn send(&mut self, value: T) -> impl Future<Output = ()> + Send;
}

trait ChannelReceiver<T>: Clone + Send {
    fn recv_vec<'a>(
        &'a self,
        element_limit: usize,
        vec: &'a mut Vec<T>,
    ) -> impl Future<Output = ()> + Send;
}

trait ChannelSyncSender<T>: Clone + Send {
    type BatchSenderSync<'a>: ChannelBatchSenderSync<T>
    where
        T: 'a;

    fn send(&mut self, value: T);

    fn autobatch<'a, F>(&'a mut self, batch_limit: usize, f: F)
    where
        F: FnOnce(&mut Self::BatchSenderSync<'a>);
}

trait ChannelBatchSenderSync<T>: Send {
    fn send(&mut self, value: T);
}

trait ChannelSyncReceiver<T>: Clone + Send {
    fn recv_vec(&self, element_limit: usize, vec: &mut Vec<T>);
}

// batch-channel, this crate

struct BatchChannel;

impl Channel for BatchChannel {
    type Sender<T: Send + 'static> = batch_channel::Sender<T>;
    type Receiver<T: Send + 'static> = batch_channel::Receiver<T>;

    fn bounded<T: Send + 'static>(capacity: usize) -> (Self::Sender<T>, Self::Receiver<T>) {
        batch_channel::bounded(capacity)
    }
}

impl ChannelSync for BatchChannel {
    type SyncSender<T: Send + 'static> = batch_channel::SyncSender<T>;
    type SyncReceiver<T: Send + 'static> = batch_channel::SyncReceiver<T>;

    fn bounded_sync<T: Send + 'static>(
        capacity: usize,
    ) -> (Self::SyncSender<T>, Self::SyncReceiver<T>) {
        batch_channel::bounded_sync(capacity)
    }
}

impl<T: Send> ChannelSender<T> for batch_channel::Sender<T> {
    type BatchSender = batch_channel::BatchSender<T>;

    fn autobatch<F>(self, batch_limit: usize, f: F) -> impl Future<Output = ()> + Send
    where
        for<'a> F: (FnOnce(&'a mut Self::BatchSender) -> BoxFuture<'a, ()>) + Send + 'static,
    {
        let f = f;
        async move {
            let f = f;
            batch_channel::Sender::autobatch(self, batch_limit, async move |tx| {
                () = f(tx).await;
                Ok(())
            })
            .await
            .expect("in this benchmark, receiver never drops")
        }
    }
}

impl<T: Send> ChannelBatchSender<T> for batch_channel::BatchSender<T> {
    fn send(&mut self, value: T) -> impl Future<Output = ()> + Send {
        async move {
            batch_channel::BatchSender::send(self, value)
                .await
                .expect("in this benchmark, receiver never drops")
        }
    }
}

impl<T: Send> ChannelReceiver<T> for batch_channel::Receiver<T> {
    fn recv_vec<'a>(
        &'a self,
        element_limit: usize,
        vec: &'a mut Vec<T>,
    ) -> impl Future<Output = ()> + Send {
        batch_channel::Receiver::recv_vec(self, element_limit, vec)
    }
}

impl<T: Send> ChannelSyncSender<T> for batch_channel::SyncSender<T> {
    type BatchSenderSync<'a>
        = batch_channel::SyncBatchSender<'a, T>
    where
        T: 'a;

    fn send(&mut self, value: T) {
        let Ok(()) = batch_channel::SyncSender::send(self, value) else {
            panic!("in this benchmark, receiver never drops");
        };
    }

    fn autobatch<'a, F>(&'a mut self, batch_limit: usize, f: F)
    where
        F: FnOnce(&mut Self::BatchSenderSync<'a>),
    {
        batch_channel::SyncSender::autobatch(self, batch_limit, |tx| {
            f(tx);
            Ok(())
        })
        .expect("in this benchmark, receiver never drops")
    }
}

impl<'a, T: Send> ChannelBatchSenderSync<T> for batch_channel::SyncBatchSender<'a, T> {
    fn send(&mut self, value: T) {
        batch_channel::SyncBatchSender::send(self, value)
            .expect("in this benchmark, receiver never drops")
    }
}

impl<T: Send> ChannelSyncReceiver<T> for batch_channel::SyncReceiver<T> {
    fn recv_vec(&self, element_limit: usize, vec: &mut Vec<T>) {
        batch_channel::SyncReceiver::recv_vec(self, element_limit, vec)
    }
}

// Kanal

struct KanalChannel;

impl Channel for KanalChannel {
    type Sender<T: Send + 'static> = kanal::AsyncSender<T>;
    type Receiver<T: Send + 'static> = kanal::AsyncReceiver<T>;

    fn bounded<T: Send + 'static>(capacity: usize) -> (Self::Sender<T>, Self::Receiver<T>) {
        kanal::bounded_async(capacity)
    }
}

impl<T: Send + 'static> ChannelSender<T> for kanal::AsyncSender<T> {
    type BatchSender = kanal::AsyncSender<T>;

    fn autobatch<F>(mut self, _batch_limit: usize, f: F) -> impl Future<Output = ()> + Send
    where
        for<'a> F: (FnOnce(&'a mut Self::BatchSender) -> BoxFuture<'a, ()>) + Send + 'static,
    {
        async move {
            f(&mut self).await;
        }
    }
}

impl<T: Send> ChannelBatchSender<T> for kanal::AsyncSender<T> {
    fn send(&mut self, value: T) -> impl Future<Output = ()> + Send {
        async move {
            kanal::AsyncSender::send(self, value)
                .await
                .expect("in this benchmark, receiver never drops")
        }
    }
}

impl<T: Send> ChannelReceiver<T> for kanal::AsyncReceiver<T> {
    fn recv_vec<'a>(
        &'a self,
        element_limit: usize,
        vec: &'a mut Vec<T>,
    ) -> impl Future<Output = ()> + Send {
        async move {
            let Ok(value) = self.recv().await else {
                return;
            };
            vec.push(value);
            // Now try to read the rest.
            for _ in 0..element_limit {
                let Ok(Some(value)) = self.try_recv() else {
                    return;
                };
                vec.push(value);
            }
        }
    }
}

impl ChannelSync for KanalChannel {
    type SyncSender<T: Send + 'static> = kanal::Sender<T>;
    type SyncReceiver<T: Send + 'static> = kanal::Receiver<T>;

    fn bounded_sync<T: Send + 'static>(
        capacity: usize,
    ) -> (Self::SyncSender<T>, Self::SyncReceiver<T>) {
        kanal::bounded(capacity)
    }
}

impl<T: Send> ChannelSyncSender<T> for kanal::Sender<T> {
    type BatchSenderSync<'a>
        = kanal::Sender<T>
    where
        T: 'a;

    fn send(&mut self, value: T) {
        let Ok(()) = kanal::Sender::send(self, value) else {
            panic!("in this benchmark, receiver never drops");
        };
    }

    fn autobatch<'a, F>(&'a mut self, _batch_limit: usize, f: F)
    where
        F: FnOnce(&mut Self::BatchSenderSync<'a>),
    {
        f(self);
    }
}

impl<T: Send> ChannelBatchSenderSync<T> for kanal::Sender<T> {
    fn send(&mut self, value: T) {
        kanal::Sender::send(self, value).expect("in this benchmark, receiver never drops")
    }
}

impl<T: Send> ChannelSyncReceiver<T> for kanal::Receiver<T> {
    fn recv_vec(&self, element_limit: usize, vec: &mut Vec<T>) {
        let Ok(value) = self.recv() else {
            return;
        };
        vec.push(value);
        // Now try to read the rest.
        for _ in 1..element_limit {
            let Ok(Some(value)) = self.try_recv() else {
                return;
            };
            vec.push(value);
        }
    }
}

// Crossbeam

struct CrossbeamChannel;

impl ChannelSync for CrossbeamChannel {
    type SyncSender<T: Send + 'static> = crossbeam::channel::Sender<T>;
    type SyncReceiver<T: Send + 'static> = crossbeam::channel::Receiver<T>;

    fn bounded_sync<T: Send + 'static>(
        capacity: usize,
    ) -> (Self::SyncSender<T>, Self::SyncReceiver<T>) {
        crossbeam::channel::bounded(capacity)
    }
}

impl<T: Send> ChannelSyncSender<T> for crossbeam::channel::Sender<T> {
    type BatchSenderSync<'a>
        = crossbeam::channel::Sender<T>
    where
        T: 'a;

    fn send(&mut self, value: T) {
        let Ok(()) = crossbeam::channel::Sender::send(self, value) else {
            panic!("in this benchmark, receiver never drops");
        };
    }

    fn autobatch<'a, F>(&'a mut self, _batch_limit: usize, f: F)
    where
        F: FnOnce(&mut Self::BatchSenderSync<'a>),
    {
        f(self);
    }
}

impl<T: Send> ChannelBatchSenderSync<T> for crossbeam::channel::Sender<T> {
    fn send(&mut self, value: T) {
        crossbeam::channel::Sender::send(self, value)
            .expect("in this benchmark, receiver never drops")
    }
}

impl<T: Send> ChannelSyncReceiver<T> for crossbeam::channel::Receiver<T> {
    fn recv_vec(&self, element_limit: usize, vec: &mut Vec<T>) {
        let Ok(value) = self.recv() else {
            return;
        };
        vec.push(value);
        // Now try to read the rest.
        for _ in 1..element_limit {
            let Ok(value) = self.try_recv() else {
                return;
            };
            vec.push(value);
        }
    }
}

// async-channel

struct AsyncChannel;

impl Channel for AsyncChannel {
    type Sender<T: Send + 'static> = async_channel::Sender<T>;
    type Receiver<T: Send + 'static> = async_channel::Receiver<T>;

    fn bounded<T: Send + 'static>(capacity: usize) -> (Self::Sender<T>, Self::Receiver<T>) {
        async_channel::bounded(capacity)
    }
}

impl<T: Send + 'static> ChannelSender<T> for async_channel::Sender<T> {
    type BatchSender = async_channel::Sender<T>;

    fn autobatch<F>(mut self, _batch_limit: usize, f: F) -> impl Future<Output = ()> + Send
    where
        for<'a> F: (FnOnce(&'a mut Self::BatchSender) -> BoxFuture<'a, ()>) + Send + 'static,
    {
        async move {
            f(&mut self).await;
        }
    }
}

impl<T: Send> ChannelBatchSender<T> for async_channel::Sender<T> {
    fn send(&mut self, value: T) -> impl Future<Output = ()> + Send {
        async move {
            async_channel::Sender::send(self, value)
                .await
                .expect("in this benchmark, receiver never drops")
        }
    }
}

impl<T: Send> ChannelReceiver<T> for async_channel::Receiver<T> {
    fn recv_vec<'a>(
        &'a self,
        element_limit: usize,
        vec: &'a mut Vec<T>,
    ) -> impl Future<Output = ()> + Send {
        async move {
            let Ok(value) = self.recv().await else {
                return;
            };
            vec.push(value);
            // Now try to read the rest.
            for _ in 1..element_limit {
                let Ok(value) = self.try_recv() else {
                    return;
                };
                vec.push(value);
            }
        }
    }
}

// Benchmark

#[derive(Copy, Clone)]
struct Options {
    tx_batch_size: usize,
    rx_batch_size: usize,
    tx_count: usize,
    rx_count: usize,
}

struct Timings {
    total: Duration,
    per_item: Duration,
}

impl Timings {
    fn print(&self) {
        println!(
            "{:?}, {:?} per item, {:.2e} items/s",
            self.total,
            self.per_item,
            1f64 / self.per_item.as_secs_f64()
        )
    }
}

async fn benchmark_throughput_async<C: Channel>(_: C, options: Options) -> Timings {
    const CAPACITY: usize = 65536;
    let send_count: usize = 2 * 1024 * 1024;
    let total_items = send_count * options.tx_count;

    let mut senders = Vec::with_capacity(options.tx_count);
    let mut receivers = Vec::with_capacity(options.rx_count);

    let now = Instant::now();

    let (tx, rx) = C::bounded(CAPACITY);
    for task_id in 0..options.tx_count {
        let tx = tx.clone();
        senders.push(tokio::spawn(
            async move {
                tx.autobatch(options.tx_batch_size, move |tx| {
                    async move {
                        for i in 0..send_count {
                            tx.send((task_id, i)).await;
                        }
                    }
                    .boxed()
                })
                .await;
            }
            .boxed(),
        ));
    }
    drop(tx);
    for _ in 0..options.rx_count {
        let rx = rx.clone();
        receivers.push(tokio::spawn(
            async move {
                let mut batch = Vec::with_capacity(options.rx_batch_size);
                loop {
                    batch.clear();
                    rx.recv_vec(options.rx_batch_size, &mut batch).await;
                    if batch.is_empty() {
                        break;
                    }
                }
            }
            .boxed(),
        ));
    }
    drop(rx);

    for r in receivers {
        () = r.await.expect("task panicked");
    }
    for s in senders {
        () = s.await.expect("task panicked");
    }

    let elapsed = now.elapsed();
    Timings {
        total: elapsed,
        per_item: elapsed / (total_items as u32),
    }
}

fn benchmark_throughput_sync<C: ChannelSync>(_: C, options: Options) -> Timings {
    const CAPACITY: usize = 65536;
    let send_count: usize = 1 * 1024 * 1024;
    let total_items = send_count * options.tx_count;

    let mut senders = Vec::with_capacity(options.tx_count);
    let mut receivers = Vec::with_capacity(options.rx_count);

    let now = Instant::now();

    let (tx, rx) = C::bounded_sync(CAPACITY);
    for task_id in 0..options.tx_count {
        let mut tx = tx.clone();
        senders.push(std::thread::spawn(move || {
            if options.tx_batch_size == 1 {
                for i in 0..send_count {
                    tx.send((task_id, i));
                }
            } else {
                tx.autobatch(options.tx_batch_size, move |tx| {
                    for i in 0..send_count {
                        tx.send((task_id, i));
                    }
                })
            }
        }));
    }
    drop(tx);
    for _ in 0..options.rx_count {
        let rx = rx.clone();
        receivers.push(std::thread::spawn(move || {
            let mut batch = Vec::with_capacity(options.rx_batch_size);
            loop {
                batch.clear();
                rx.recv_vec(options.rx_batch_size, &mut batch);
                if batch.is_empty() {
                    break;
                }
            }
        }));
    }
    drop(rx);

    for r in receivers {
        () = r.join().expect("thread panicked");
    }
    for s in senders {
        () = s.join().expect("thread panicked");
    }

    let elapsed = now.elapsed();
    Timings {
        total: elapsed,
        per_item: elapsed / (total_items as u32),
    }
}

// These exist to allow `cargo bench` to run this benchmark while
// selecting filters from other
#[derive(Debug, Subcommand)]
enum Commands {
    Throughput {
        #[arg(long)]
        bench: bool,
    },
    Alloc {
        #[arg(long)]
        bench: bool,
    },
    Async {
        #[arg(long)]
        bench: bool,
    },
    Uncontended {
        #[arg(long)]
        bench: bool,
    },
}

#[derive(Parser, Debug)]
struct Args {
    #[arg(long)]
    bench: bool,

    #[arg(long)]
    csv: bool,

    #[arg(long)]
    threads: Option<usize>,

    #[arg(long, action=clap::ArgAction::Set, default_value_t=true)]
    sync: bool,

    #[arg(long, action=clap::ArgAction::Set, default_value_t=true)]
    r#async: bool,

    #[arg(long)]
    txs: Option<Vec<usize>>,

    #[arg(long)]
    rxs: Option<Vec<usize>>,

    #[arg(long)]
    tx_batch: Option<Vec<usize>>,

    #[arg(long)]
    rx_batch: Option<Vec<usize>>,

    #[command(subcommand)]
    command: Option<Commands>,
}

lazy_static! {
    static ref ARGS: Args = Args::parse();
}

const DEFAULT_TASK_COUNTS: &[usize] = &[1, 4];

const DEFAULT_BATCH_SIZES: &[usize] = &[1, 2, 4, 8, 16, 32, 64, 128, 256];

fn main() -> anyhow::Result<()> {
    match ARGS.command {
        Some(Commands::Throughput { .. }) => (),
        None => (),
        _ => {
            return Ok(());
        }
    }

    let thread_count = ARGS
        .threads
        .unwrap_or(std::thread::available_parallelism()?.get());

    let runtime = tokio::runtime::Builder::new_multi_thread()
        .worker_threads(thread_count)
        .build()
        .expect("failed to create tokio runtime");

    let task_counts: Vec<(usize, usize)> = match (&ARGS.txs, &ARGS.rxs) {
        (Some(tx), Some(rx)) => tx
            .iter()
            .copied()
            .cartesian_product(rx.iter().copied())
            .collect(),
        (Some(tx), None) => tx
            .iter()
            .copied()
            .cartesian_product(DEFAULT_TASK_COUNTS.iter().copied())
            .collect(),
        (None, Some(rx)) => DEFAULT_TASK_COUNTS
            .iter()
            .copied()
            .cartesian_product(rx.iter().copied())
            .collect(),
        (None, None) => DEFAULT_TASK_COUNTS
            .iter()
            .copied()
            .cartesian_product(DEFAULT_TASK_COUNTS.iter().copied())
            .collect(),
    };

    let batch_sizes: Vec<(usize, usize)> = match (&ARGS.tx_batch, &ARGS.rx_batch) {
        (Some(tx_batch), Some(rx_batch)) => tx_batch
            .iter()
            .copied()
            .cartesian_product(rx_batch.iter().copied())
            .collect(),
        (Some(tx_batch), None) => tx_batch
            .iter()
            .copied()
            .cartesian_product(DEFAULT_BATCH_SIZES.iter().copied())
            .collect(),
        (None, Some(rx_batch)) => DEFAULT_BATCH_SIZES
            .iter()
            .copied()
            .cartesian_product(rx_batch.iter().copied())
            .collect(),
        (None, None) => DEFAULT_BATCH_SIZES
            .iter()
            .copied()
            .map(|s| (s, s))
            .collect(),
    };

    async fn bench_async<C: Channel>(name: &str, options: Options, channel: C) {
        if !ARGS.csv {
            print!("    {: <13}: ", name);
        }
        let timings = benchmark_throughput_async(channel, options).await;
        if ARGS.csv {
            println!(
                "async,{},{},{},{},{},{},{}",
                name,
                options.tx_count,
                options.rx_count,
                options.tx_batch_size,
                options.rx_batch_size,
                timings.total.as_nanos(),
                timings.per_item.as_nanos()
            );
        } else {
            timings.print();
        }
    }

    fn bench_sync<C: ChannelSync>(name: &str, options: Options, channel: C) {
        if !ARGS.csv {
            print!("    {: <13}: ", name);
        }
        let timings = benchmark_throughput_sync(channel, options);
        if ARGS.csv {
            println!(
                "sync,{},{},{},{},{},{},{}",
                name,
                options.tx_count,
                options.rx_count,
                options.tx_batch_size,
                options.rx_batch_size,
                timings.total.as_nanos(),
                timings.per_item.as_nanos()
            );
        } else {
            timings.print();
        }
    }

    let run_batch_async_with_options = |options| {
        runtime.block_on(bench_async("batch-channel", options, BatchChannel));
        runtime.block_on(bench_async("kanal", options, KanalChannel));
        runtime.block_on(bench_async("async-channel", options, AsyncChannel));
    };

    let run_batch_sync_with_options = |options| {
        bench_sync("batch-channel", options, BatchChannel);
        bench_sync("kanal", options, KanalChannel);
        bench_sync("crossbeam", options, CrossbeamChannel);
    };

    if ARGS.csv {
        println!("mode,channel,tx,rx,tx_batch_size,rx_batch_size,total_ns,per_item_ns");
    }

    for (tx_count, rx_count) in task_counts.iter().copied() {
        if ARGS.r#async {
            if !ARGS.csv {
                println!();
                println!("throughput async (tx={} rx={})", tx_count, rx_count);
            }
            for (tx_batch_size, rx_batch_size) in batch_sizes.iter().copied() {
                if !ARGS.csv {
                    println!("  tx_batch={tx_batch_size}, rx_batch={rx_batch_size}");
                }

                run_batch_async_with_options(Options {
                    tx_batch_size,
                    rx_batch_size,
                    tx_count,
                    rx_count,
                });
            }
        }

        if ARGS.sync {
            if !ARGS.csv {
                println!();
                println!("throughput sync (tx={} rx={})", tx_count, rx_count);
            }
            for (tx_batch_size, rx_batch_size) in batch_sizes.iter().copied() {
                if !ARGS.csv {
                    println!("  tx_batch={tx_batch_size}, rx_batch={rx_batch_size}");
                }

                run_batch_sync_with_options(Options {
                    tx_batch_size,
                    rx_batch_size,
                    tx_count,
                    rx_count,
                });
            }
        }
    }

    Ok(())
}