Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,25 @@ codegen-units = 1
bench = false # Don't disturb criterion command line parsing

[[bench]]
name = "single_thread_single_byte"
name = "chunks"
harness = false

[[bench]]
name = "single_thread_two_bytes"
name = "const_push_pop"
harness = false

[[bench]]
name = "single_thread_with_chunks"
name = "push_pop"
harness = false

[[bench]]
name = "two_threads"
name = "single_thread_single_byte"
harness = false

[[bench]]
name = "two_threads_with_chunks"
name = "single_thread_two_bytes"
harness = false

[[bench]]
name = "two_threads_const"
name = "single_thread_with_chunks"
harness = false
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ Performance

Measuring the performance of a data structure for inter-thread communication
can be quite brittle and the results depend on many factors.
A few performance comparisons between competing crates are shown in
[issue #39](https://github.com/mgeier/rtrb/issues/39),
but like all benchmarks, they are deeply flawed and to be taken with a grain of salt.
A few benchmarks for performance comparisons between competing crates
are available at the sub-directory
[`performance-comparison/`](https://github.com/mgeier/rtrb/tree/main/performance-comparison)
and some results thereof are shown in
[issue #39](https://github.com/mgeier/rtrb/issues/39).
Like all benchmarks, they are deeply flawed and to be taken with a grain of salt.
You should make your own measurements that are relevant to your usage patterns.
Feel free to share your own results by commenting on that issue.

Expand Down
12 changes: 7 additions & 5 deletions benches/two_threads_with_chunks.rs → benches/chunks.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(clippy::incompatible_msrv)]

macro_rules! create_two_threads_with_chunks_benchmark {
macro_rules! create_chunks_benchmark {
($($id:literal, $create:expr, $push:expr, $pop:expr, ::)+) => {

use std::convert::TryFrom as _;
Expand Down Expand Up @@ -36,7 +36,9 @@ $(
assert_eq!(dst, [40, 20, 30]);
)+

let mut group_large = criterion.benchmark_group("large-with-chunks");
let mut group_large = criterion.benchmark_group("chunks-large");
group_large.plot_config(criterion::PlotConfiguration::default()
.summary_scale(criterion::AxisScale::Logarithmic));
$(
group_large.bench_function($id, |b| {
b.iter_custom(|iters| {
Expand Down Expand Up @@ -139,7 +141,7 @@ $(

let queue_sizes = [4096];

let mut group_write_chunk = criterion.benchmark_group("eager-write-chunk");
let mut group_write_chunk = criterion.benchmark_group("chunks-eager-write");
group_write_chunk.plot_config(criterion::PlotConfiguration::default()
.summary_scale(criterion::AxisScale::Logarithmic));
$(
Expand Down Expand Up @@ -209,7 +211,7 @@ $(
)+
group_write_chunk.finish();

let mut group_read_chunk = criterion.benchmark_group("eager-read-chunk");
let mut group_read_chunk = criterion.benchmark_group("chunks-eager-read");
group_read_chunk.plot_config(criterion::PlotConfiguration::default()
.summary_scale(criterion::AxisScale::Logarithmic));
$(
Expand Down Expand Up @@ -275,7 +277,7 @@ criterion_main!(benches);

use std::io::{Read as _, Write as _};

create_two_threads_with_chunks_benchmark!(
create_chunks_benchmark!(
"write-read",
rtrb::RingBuffer::new,
|p, s| match p.write(s) {
Expand Down
4 changes: 2 additions & 2 deletions benches/two_threads_const.rs → benches/const_push_pop.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
macro_rules! create_two_threads_const_benchmark {
macro_rules! create_const_push_pop_benchmark {
($($id:literal, $create:tt, $push:expr, $pop:expr,::)+) => {

use std::hint::black_box;
Expand Down Expand Up @@ -109,7 +109,7 @@ criterion_main!(benches);
};
}

create_two_threads_const_benchmark! {
create_const_push_pop_benchmark! {
"rtrb",
{ ($N:expr) => {
rtrb::RingBuffer::new($N)
Expand Down
8 changes: 6 additions & 2 deletions benches/two_threads.rs → benches/push_pop.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
macro_rules! create_two_threads_benchmark {
macro_rules! create_push_pop_benchmark {
($($id:literal, $create:expr, $push:expr, $pop:expr,::)+) => {

use std::convert::TryInto as _;
Expand Down Expand Up @@ -32,6 +32,8 @@ $(
)+

let mut group_large = criterion.benchmark_group("large");
group_large.plot_config(criterion::PlotConfiguration::default()
.summary_scale(criterion::AxisScale::Logarithmic));
group_large.throughput(criterion::Throughput::Bytes(1));
$(
group_large.bench_function($id, |b| {
Expand Down Expand Up @@ -118,6 +120,8 @@ $(
group_large.finish();

let mut group_small = criterion.benchmark_group("small");
group_small.plot_config(criterion::PlotConfiguration::default()
.summary_scale(criterion::AxisScale::Logarithmic));
group_small.throughput(criterion::Throughput::Bytes(1));
$(
group_small.bench_function($id, |b| {
Expand Down Expand Up @@ -286,7 +290,7 @@ criterion_main!(benches);
};
}

create_two_threads_benchmark!(
create_push_pop_benchmark!(
"rtrb",
rtrb::RingBuffer::new,
|p, i| p.push(i).is_ok(),
Expand Down
6 changes: 3 additions & 3 deletions performance-comparison/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ codegen-units = 1
bench = false # Don't disturb criterion command line parsing

[[bench]]
name = "two_threads"
name = "chunks"
harness = false

[[bench]]
name = "two_threads_with_chunks"
name = "const_push_pop"
harness = false

[[bench]]
name = "two_threads_const"
name = "push_pop"
harness = false
22 changes: 22 additions & 0 deletions performance-comparison/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Performance Comparison between `rtrb` and Other Crates
======================================================

Run all benchmarks (takes a long time):

cargo bench

Run a single benchmark file (see `benches/` subdirectory):

cargo bench --bench push_pop

Run all benchmarks that match a substring:

cargo bench --bench push_pop -- eager-push

List all available benchmarks:

cargo bench -- --list

Some results are available in
[issue #39](https://github.com/mgeier/rtrb/issues/39),
feel free to add your own results there!
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[path = "../../benches/two_threads_with_chunks.rs"]
#[path = "../../benches/chunks.rs"]
#[macro_use]
mod two_threads_with_chunks;
mod chunks;

use core::num::NonZeroUsize;

Expand All @@ -10,7 +10,7 @@ use ringbuf::traits::Consumer as _;
use ringbuf::traits::Producer as _;
use ringbuf::traits::Split as _;

create_two_threads_with_chunks_benchmark!(
create_chunks_benchmark!(
"1-gil",
|capacity| gil::spsc::channel(NonZeroUsize::new(capacity).unwrap()),
|p, s| {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#[path = "../../benches/two_threads_const.rs"]
#[path = "../../benches/const_push_pop.rs"]
#[macro_use]
mod two_threads_const;
mod const_push_pop;

use ringbuf::traits::*;

create_two_threads_const_benchmark!(
create_const_push_pop_benchmark!(
"rtrb",
{ ($N:expr) => {
rtrb::RingBuffer::new($N)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#[path = "../../benches/two_threads.rs"]
#[path = "../../benches/push_pop.rs"]
#[macro_use]
mod two_threads;
mod push_pop;

use core::num::NonZeroUsize;

use ringbuf::traits::Consumer as _;
use ringbuf::traits::Producer as _;
use ringbuf::traits::Split as _;

create_two_threads_benchmark!(
create_push_pop_benchmark!(
"0-rtrb",
rtrb::RingBuffer::new,
|p, i| p.push(i).is_ok(),
Expand Down