Skip to content

Commit

Permalink
sync: add mpsc benchmarks of small, medium, and large message types
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Mar 13, 2019
1 parent dbb04e3 commit b85ab36
Showing 1 changed file with 92 additions and 8 deletions.
100 changes: 92 additions & 8 deletions tokio-sync/benches/mpsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,40 @@ 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;
use test::{self, Bencher};
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::<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_channel::<super::Medium>());
})
}
#[bench]
fn bounded_new_large(b: &mut Bencher) {
b.iter(|| {
let _ = test::black_box(&unbounded_channel::<i32>());
let _ = test::black_box(&channel::<super::Large>(1_000));
})
}

#[bench]
fn unbounded_new_large(b: &mut Bencher) {
b.iter(|| {
let _ = test::black_box(&unbounded_channel::<super::Large>());
})
}

Expand All @@ -38,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);
Expand Down Expand Up @@ -126,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(|| {
Expand Down Expand Up @@ -237,16 +280,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>());
})
}

Expand All @@ -263,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);
Expand Down Expand Up @@ -351,6 +421,20 @@ 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(|| {
Expand Down

0 comments on commit b85ab36

Please sign in to comment.