diff --git a/tokio-sync/benches/mpsc.rs b/tokio-sync/benches/mpsc.rs index 31998f4acb4..d182319bd60 100644 --- a/tokio-sync/benches/mpsc.rs +++ b/tokio-sync/benches/mpsc.rs @@ -6,10 +6,24 @@ extern crate test; mod tokio { use tokio_sync::mpsc::*; - use futures::{Async, Stream, Sink}; + use futures::{future, Async, Future, Stream, Sink}; use test::{self, Bencher}; use std::thread; + #[bench] + fn bounded_new(b: &mut Bencher) { + b.iter(|| { + let _ = test::black_box(&channel::(1_000)); + }) + } + + #[bench] + fn unbounded_new(b: &mut Bencher) { + b.iter(|| { + let _ = test::black_box(&unbounded_channel::()); + }) + } + #[bench] fn send_one_message(b: &mut Bencher) { b.iter(|| { @@ -24,7 +38,56 @@ mod tokio { } #[bench] - fn unbounded_uncontended_1(b: &mut Bencher) { + fn bounded_rx_not_ready(b: &mut Bencher) { + let (_tx, mut rx) = channel::(1_000); + b.iter(|| { + future::lazy(|| { + assert!(rx.poll().unwrap().is_not_ready()); + + Ok::<_, ()>(()) + }).wait().unwrap(); + }) + } + + #[bench] + fn bounded_tx_poll_ready(b: &mut Bencher) { + let (mut tx, rx) = channel::(1); + b.iter(|| { + future::lazy(|| { + assert!(tx.poll_ready().unwrap().is_ready()); + + Ok::<_, ()>(()) + }).wait().unwrap(); + }) + } + + #[bench] + fn bounded_tx_poll_not_ready(b: &mut Bencher) { + let (mut tx, rx) = channel::(1); + tx.try_send(1).unwrap(); + b.iter(|| { + future::lazy(|| { + assert!(tx.poll_ready().unwrap().is_not_ready()); + + Ok::<_, ()>(()) + }).wait().unwrap(); + }) + } + + #[bench] + fn unbounded_rx_not_ready(b: &mut Bencher) { + let (_tx, mut rx) = unbounded_channel::(); + b.iter(|| { + future::lazy(|| { + assert!(rx.poll().unwrap().is_not_ready()); + + Ok::<_, ()>(()) + }).wait().unwrap(); + }) + } + + #[bench] + fn bounded_uncontended_1(b: &mut Bencher) { b.iter(|| { let (mut tx, mut rx) = channel(1_000); @@ -37,7 +100,7 @@ mod tokio { } #[bench] - fn unbounded_uncontended_2(b: &mut Bencher) { + fn bounded_uncontended_2(b: &mut Bencher) { b.iter(|| { let (mut tx, mut rx) = channel(1000); @@ -143,11 +206,25 @@ mod tokio { } mod legacy { - use futures::{Async, Stream, Sink}; + use futures::{future, Async, Future, Stream, Sink}; use futures::sync::mpsc::*; use test::{self, Bencher}; use std::thread; + #[bench] + fn bounded_new(b: &mut Bencher) { + b.iter(|| { + let _ = test::black_box(&channel::(1_000)); + }) + } + + #[bench] + fn unbounded_new(b: &mut Bencher) { + b.iter(|| { + let _ = test::black_box(&unbounded::()); + }) + } + #[bench] fn send_one_message(b: &mut Bencher) { b.iter(|| { @@ -161,6 +238,55 @@ mod legacy { }) } + #[bench] + fn bounded_rx_not_ready(b: &mut Bencher) { + let (_tx, mut rx) = channel::(1_000); + b.iter(|| { + future::lazy(|| { + assert!(rx.poll().unwrap().is_not_ready()); + + Ok::<_, ()>(()) + }).wait().unwrap(); + }) + } + + #[bench] + fn bounded_tx_poll_ready(b: &mut Bencher) { + let (mut tx, rx) = channel::(0); + b.iter(|| { + future::lazy(|| { + assert!(tx.poll_ready().unwrap().is_ready()); + + Ok::<_, ()>(()) + }).wait().unwrap(); + }) + } + + #[bench] + fn bounded_tx_poll_not_ready(b: &mut Bencher) { + let (mut tx, rx) = channel::(0); + tx.try_send(1).unwrap(); + b.iter(|| { + future::lazy(|| { + assert!(tx.poll_ready().unwrap().is_not_ready()); + + Ok::<_, ()>(()) + }).wait().unwrap(); + }) + } + + #[bench] + fn unbounded_rx_not_ready(b: &mut Bencher) { + let (_tx, mut rx) = unbounded::(); + b.iter(|| { + future::lazy(|| { + assert!(rx.poll().unwrap().is_not_ready()); + + Ok::<_, ()>(()) + }).wait().unwrap(); + }) + } + #[bench] fn unbounded_uncontended_1(b: &mut Bencher) { b.iter(|| { diff --git a/tokio-sync/benches/oneshot.rs b/tokio-sync/benches/oneshot.rs index cfb343f1471..97dd1ee9430 100644 --- a/tokio-sync/benches/oneshot.rs +++ b/tokio-sync/benches/oneshot.rs @@ -9,6 +9,13 @@ mod tokio { use tokio_sync::oneshot; use test::{Bencher}; + #[bench] + fn new(b: &mut Bencher) { + b.iter(|| { + let _ = ::test::black_box(&oneshot::channel::()); + }) + } + #[bench] fn same_thread_send_recv(b: &mut Bencher) { b.iter(|| { @@ -113,6 +120,13 @@ mod legacy { use futures::sync::oneshot; use test::{Bencher}; + #[bench] + fn new(b: &mut Bencher) { + b.iter(|| { + let _ = ::test::black_box(&oneshot::channel::()); + }) + } + #[bench] fn same_thread_send_recv(b: &mut Bencher) { b.iter(|| {