diff options
author | Alex Crichton <alex@alexcrichton.com> | 2016-11-10 20:10:02 -0800 |
---|---|---|
committer | Alex Crichton <alex@alexcrichton.com> | 2016-11-10 20:10:02 -0800 |
commit | 3d69a8b7d0d653457096e9b95a6138ff5691386c (patch) | |
tree | c0644675476b7818bfac402b1dd610ca8f44ba12 /benches | |
parent | bbea632e043ce2a45cf26fb4c9e2c26bb2e63a4c (diff) |
Add a benchmark for futures channel latency
Diffstat (limited to 'benches')
-rw-r--r-- | benches/latency.rs | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/benches/latency.rs b/benches/latency.rs index 5b73d44a..4dfc708a 100644 --- a/benches/latency.rs +++ b/benches/latency.rs @@ -7,16 +7,15 @@ extern crate tokio_core; use std::io; use std::net::SocketAddr; +use std::thread; +use futures::sync::oneshot; +use futures::sync::spsc; use futures::{Future, Poll, Sink, Stream}; +use test::Bencher; +use tokio_core::channel::Sender; use tokio_core::net::UdpSocket; use tokio_core::reactor::Core; -use tokio_core::channel::Sender; - -use test::Bencher; -use std::thread; - -use futures::sync::oneshot; /// UDP echo server struct EchoServer { @@ -96,7 +95,7 @@ fn udp_echo_latency(b: &mut Bencher) { } #[bench] -fn channel_latency(b: &mut Bencher) { +fn tokio_channel_latency(b: &mut Bencher) { let (tx, rx) = oneshot::channel(); let child = thread::spawn(move || { @@ -131,3 +130,28 @@ fn channel_latency(b: &mut Bencher) { drop(in_tx); child.join().unwrap(); } + +#[bench] +fn futures_channel_latency(b: &mut Bencher) { + let (mut in_tx, in_rx) = spsc::channel(); + let (out_tx, out_rx) = spsc::channel::<_, ()>(); + + let child = thread::spawn(|| out_tx.send_all(in_rx).wait()); + let mut rx_iter = out_rx.wait(); + + // warmup phase; for some reason initial couple of runs are much slower + // + // TODO: Describe the exact reasons; caching? branch predictor? lazy closures? + for _ in 0..8 { + in_tx.start_send(Ok(Ok(1usize))).unwrap(); + let _ = rx_iter.next(); + } + + b.iter(|| { + in_tx.start_send(Ok(Ok(1usize))).unwrap(); + let _ = rx_iter.next(); + }); + + drop(in_tx); + child.join().unwrap().unwrap(); +} |