Skip to content

Commit

Permalink
Add poll_ready and constructor benchmarks for tokio-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Feb 14, 2019
1 parent ec22fb9 commit 49774f6
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 4 deletions.
134 changes: 130 additions & 4 deletions tokio-sync/benches/mpsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<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(|| {
Expand All @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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::<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(|| {
Expand All @@ -161,6 +238,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(|| {
Expand Down
14 changes: 14 additions & 0 deletions tokio-sync/benches/oneshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<i32>());
})
}

#[bench]
fn same_thread_send_recv(b: &mut Bencher) {
b.iter(|| {
Expand Down Expand Up @@ -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::<i32>());
})
}

#[bench]
fn same_thread_send_recv(b: &mut Bencher) {
b.iter(|| {
Expand Down

0 comments on commit 49774f6

Please sign in to comment.