summaryrefslogtreecommitdiffstats
path: root/tokio-sync
diff options
context:
space:
mode:
authorSean McArthur <sean@seanmonstar.com>2019-02-11 14:37:00 -0800
committerSean McArthur <sean@seanmonstar.com>2019-02-14 13:26:53 -0800
commit49774f6af1bd6a5b1b2c39169b3fbc7b3f525747 (patch)
tree86408af4687003ac0cfca4518ae1267a1c3c0ae9 /tokio-sync
parentec22fb984317536f3846e74ae581361b65627e16 (diff)
Add poll_ready and constructor benchmarks for tokio-sync
Diffstat (limited to 'tokio-sync')
-rw-r--r--tokio-sync/benches/mpsc.rs134
-rw-r--r--tokio-sync/benches/oneshot.rs14
2 files changed, 144 insertions, 4 deletions
diff --git a/tokio-sync/benches/mpsc.rs b/tokio-sync/benches/mpsc.rs
index 31998f4a..d182319b 100644
--- a/tokio-sync/benches/mpsc.rs
+++ b/tokio-sync/benches/mpsc.rs
@@ -6,11 +6,25 @@ 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::<i32>(1_000));
+ })
+ }
+
+ #[bench]
+ fn unbounded_new(b: &mut Bencher) {
+ b.iter(|| {
+ let _ = test::black_box(&unbounded_channel::<i32>());
+ })
+ }
+
+ #[bench]
fn send_one_message(b: &mut Bencher) {
b.iter(|| {
let (mut tx, mut rx) = channel(1_000);
@@ -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::<i32>(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::<i32>(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::<i32>(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::<i32>();
+ 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,12 +206,26 @@ 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::<i32>(1_000));
+ })
+ }
+
+ #[bench]
+ fn unbounded_new(b: &mut Bencher) {
+ b.iter(|| {
+ let _ = test::black_box(&unbounded::<i32>());
+ })
+ }
+
+ #[bench]
fn send_one_message(b: &mut Bencher) {
b.iter(|| {
let (mut tx, mut rx) = channel(1_000);
@@ -162,6 +239,55 @@ mod legacy {
}
#[bench]
+ fn bounded_rx_not_ready(b: &mut Bencher) {
+ let (_tx, mut rx) = channel::<i32>(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::<i32>(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::<i32>(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::<i32>();
+ b.iter(|| {
+ future::lazy(|| {
+ assert!(rx.poll().unwrap().is_not_ready());
+
+ Ok::<_, ()>(())
+ }).wait().unwrap();
+ })
+ }
+
+ #[bench]
fn unbounded_uncontended_1(b: &mut Bencher) {
b.iter(|| {
let (tx, mut rx) = unbounded();
diff --git a/tokio-sync/benches/oneshot.rs b/tokio-sync/benches/oneshot.rs
index cfb343f1..97dd1ee9 100644
--- a/tokio-sync/benches/oneshot.rs
+++ b/tokio-sync/benches/oneshot.rs
@@ -10,6 +10,13 @@ mod tokio {
use test::{Bencher};
#[bench]
+ fn new(b: &mut Bencher) {
+ b.iter(|| {
+ let _ = ::test::black_box(&oneshot::channel::<i32>());
+ })
+ }
+
+ #[bench]
fn same_thread_send_recv(b: &mut Bencher) {
b.iter(|| {
let (tx, mut rx) = oneshot::channel();
@@ -114,6 +121,13 @@ mod legacy {
use test::{Bencher};
#[bench]
+ fn new(b: &mut Bencher) {
+ b.iter(|| {
+ let _ = ::test::black_box(&oneshot::channel::<i32>());
+ })
+ }
+
+ #[bench]
fn same_thread_send_recv(b: &mut Bencher) {
b.iter(|| {
let (tx, mut rx) = oneshot::channel();