diff --git a/tokio-sync/benches/mpsc.rs b/tokio-sync/benches/mpsc.rs index 79822886e..6bb0aac18 100644 --- a/tokio-sync/benches/mpsc.rs +++ b/tokio-sync/benches/mpsc.rs @@ -5,6 +5,9 @@ extern crate futures; extern crate test; extern crate tokio_sync; +type Medium = [usize; 64]; +type Large = [Medium; 64]; + mod tokio { use futures::{future, Async, Future, Sink, Stream}; use std::thread; @@ -12,16 +15,29 @@ mod tokio { use tokio_sync::mpsc::*; #[bench] - fn bounded_new(b: &mut Bencher) { + fn bounded_new_medium(b: &mut Bencher) { b.iter(|| { - let _ = test::black_box(&channel::(1_000)); + let _ = test::black_box(&channel::(1_000)); }) } #[bench] - fn unbounded_new(b: &mut Bencher) { + fn unbounded_new_medium(b: &mut Bencher) { b.iter(|| { - let _ = test::black_box(&unbounded_channel::()); + let _ = test::black_box(&unbounded_channel::()); + }) + } + #[bench] + fn bounded_new_large(b: &mut Bencher) { + b.iter(|| { + let _ = test::black_box(&channel::(1_000)); + }) + } + + #[bench] + fn unbounded_new_large(b: &mut Bencher) { + b.iter(|| { + let _ = test::black_box(&unbounded_channel::()); }) } @@ -38,6 +54,19 @@ mod tokio { }) } + #[bench] + fn send_one_message_large(b: &mut Bencher) { + b.iter(|| { + let (mut tx, mut rx) = channel::(1_000); + + // Send + let _ = tx.try_send([[0; 64]; 64]); + + // Receive + let _ = test::black_box(&rx.poll()); + }) + } + #[bench] fn bounded_rx_not_ready(b: &mut Bencher) { let (_tx, mut rx) = channel::(1_000); @@ -126,6 +155,19 @@ mod tokio { }) } + #[bench] + fn bounded_uncontended_1_large(b: &mut Bencher) { + b.iter(|| { + let (mut tx, mut rx) = channel::(1_000); + + for i in 0..1000 { + let _ = tx.try_send([[i; 64]; 64]); + // No need to create a task, because poll is not going to park. + let _ = test::black_box(&rx.poll()); + } + }) + } + #[bench] fn bounded_uncontended_2(b: &mut Bencher) { b.iter(|| { @@ -237,16 +279,30 @@ mod legacy { use test::{self, Bencher}; #[bench] - fn bounded_new(b: &mut Bencher) { + fn bounded_new_medium(b: &mut Bencher) { b.iter(|| { - let _ = test::black_box(&channel::(1_000)); + let _ = test::black_box(&channel::(1_000)); }) } #[bench] - fn unbounded_new(b: &mut Bencher) { + fn unbounded_new_medium(b: &mut Bencher) { b.iter(|| { - let _ = test::black_box(&unbounded::()); + let _ = test::black_box(&unbounded::()); + }) + } + + #[bench] + fn bounded_new_large(b: &mut Bencher) { + b.iter(|| { + let _ = test::black_box(&channel::(1_000)); + }) + } + + #[bench] + fn unbounded_new_large(b: &mut Bencher) { + b.iter(|| { + let _ = test::black_box(&unbounded::()); }) } @@ -263,6 +319,19 @@ mod legacy { }) } + #[bench] + fn send_one_message_large(b: &mut Bencher) { + b.iter(|| { + let (mut tx, mut rx) = channel::(1_000); + + // Send + let _ = tx.try_send([[0; 64]; 64]); + + // Receive + let _ = test::black_box(&rx.poll()); + }) + } + #[bench] fn bounded_rx_not_ready(b: &mut Bencher) { let (_tx, mut rx) = channel::(1_000); @@ -351,6 +420,19 @@ mod legacy { }) } + #[bench] + fn unbounded_uncontended_1_large(b: &mut Bencher) { + b.iter(|| { + let (tx, mut rx) = unbounded::(); + + for i in 0..1000 { + let _ = UnboundedSender::unbounded_send(&tx, [[i; 64]; 64]); + // No need to create a task, because poll is not going to park. + let _ = test::black_box(&rx.poll()); + } + }) + } + #[bench] fn unbounded_uncontended_2(b: &mut Bencher) { b.iter(|| {