summaryrefslogtreecommitdiffstats
path: root/tokio-sync
diff options
context:
space:
mode:
authorSean McArthur <sean@seanmonstar.com>2019-03-13 11:00:42 -0700
committerGitHub <noreply@github.com>2019-03-13 11:00:42 -0700
commit1bc6d75543a08cb690f51c0a2ece06f29af65b80 (patch)
tree8f20f62590291dea34038bf954b8c41d1eef2f9d /tokio-sync
parent27148d6110aa36de2b225e2a9f10ccd6e743cc0f (diff)
sync: add mpsc benchmarks of small, medium, and large message types (#982)
Diffstat (limited to 'tokio-sync')
-rw-r--r--tokio-sync/benches/mpsc.rs98
1 files changed, 90 insertions, 8 deletions
diff --git a/tokio-sync/benches/mpsc.rs b/tokio-sync/benches/mpsc.rs
index 79822886..6bb0aac1 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::<super::Medium>(1_000));
+ })
+ }
+
+ #[bench]
+ fn unbounded_new_medium(b: &mut Bencher) {
+ b.iter(|| {
+ let _ = test::black_box(&unbounded_channel::<super::Medium>());
+ })
+ }
+ #[bench]
+ fn bounded_new_large(b: &mut Bencher) {
b.iter(|| {
- let _ = test::black_box(&channel::<i32>(1_000));
+ let _ = test::black_box(&channel::<super::Large>(1_000));
})
}
#[bench]
- fn unbounded_new(b: &mut Bencher) {
+ fn unbounded_new_large(b: &mut Bencher) {
b.iter(|| {
- let _ = test::black_box(&unbounded_channel::<i32>());
+ let _ = test::black_box(&unbounded_channel::<super::Large>());
})
}
@@ -39,6 +55,19 @@ mod tokio {
}
#[bench]
+ fn send_one_message_large(b: &mut Bencher) {
+ b.iter(|| {
+ let (mut tx, mut rx) = channel::<super::Large>(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::<i32>(1_000);
b.iter(|| {
@@ -127,6 +156,19 @@ mod tokio {
}
#[bench]
+ fn bounded_uncontended_1_large(b: &mut Bencher) {
+ b.iter(|| {
+ let (mut tx, mut rx) = channel::<super::Large>(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(|| {
let (mut tx, mut rx) = channel(1000);
@@ -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::<i32>(1_000));
+ let _ = test::black_box(&channel::<super::Medium>(1_000));
})
}
#[bench]
- fn unbounded_new(b: &mut Bencher) {
+ fn unbounded_new_medium(b: &mut Bencher) {
b.iter(|| {
- let _ = test::black_box(&unbounded::<i32>());
+ let _ = test::black_box(&unbounded::<super::Medium>());
+ })
+ }
+
+ #[bench]
+ fn bounded_new_large(b: &mut Bencher) {
+ b.iter(|| {
+ let _ = test::black_box(&channel::<super::Large>(1_000));
+ })
+ }
+
+ #[bench]
+ fn unbounded_new_large(b: &mut Bencher) {
+ b.iter(|| {
+ let _ = test::black_box(&unbounded::<super::Large>());
})
}
@@ -264,6 +320,19 @@ mod legacy {
}
#[bench]
+ fn send_one_message_large(b: &mut Bencher) {
+ b.iter(|| {
+ let (mut tx, mut rx) = channel::<super::Large>(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::<i32>(1_000);
b.iter(|| {
@@ -352,6 +421,19 @@ mod legacy {
}
#[bench]
+ fn unbounded_uncontended_1_large(b: &mut Bencher) {
+ b.iter(|| {
+ let (tx, mut rx) = unbounded::<super::Large>();
+
+ 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(|| {
let (tx, mut rx) = unbounded();