diff --git a/Cargo.toml b/Cargo.toml index 09bb3698..13e340d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/README.md b/README.md index b119e8d8..26be18e0 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/benches/two_threads_with_chunks.rs b/benches/chunks.rs similarity index 96% rename from benches/two_threads_with_chunks.rs rename to benches/chunks.rs index d8266db4..3b261378 100644 --- a/benches/two_threads_with_chunks.rs +++ b/benches/chunks.rs @@ -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 _; @@ -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| { @@ -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)); $( @@ -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)); $( @@ -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) { diff --git a/benches/two_threads_const.rs b/benches/const_push_pop.rs similarity index 97% rename from benches/two_threads_const.rs rename to benches/const_push_pop.rs index ed6b7bc0..9870dc30 100644 --- a/benches/two_threads_const.rs +++ b/benches/const_push_pop.rs @@ -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; @@ -109,7 +109,7 @@ criterion_main!(benches); }; } -create_two_threads_const_benchmark! { +create_const_push_pop_benchmark! { "rtrb", { ($N:expr) => { rtrb::RingBuffer::new($N) diff --git a/benches/two_threads.rs b/benches/push_pop.rs similarity index 97% rename from benches/two_threads.rs rename to benches/push_pop.rs index 7856ed48..10aec1f5 100644 --- a/benches/two_threads.rs +++ b/benches/push_pop.rs @@ -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 _; @@ -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| { @@ -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| { @@ -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(), diff --git a/performance-comparison/Cargo.toml b/performance-comparison/Cargo.toml index 84dc02de..c55b73dc 100644 --- a/performance-comparison/Cargo.toml +++ b/performance-comparison/Cargo.toml @@ -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 diff --git a/performance-comparison/README.md b/performance-comparison/README.md new file mode 100644 index 00000000..92040dcc --- /dev/null +++ b/performance-comparison/README.md @@ -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! diff --git a/performance-comparison/benches/two_threads_with_chunks.rs b/performance-comparison/benches/chunks.rs similarity index 90% rename from performance-comparison/benches/two_threads_with_chunks.rs rename to performance-comparison/benches/chunks.rs index a709e221..597fe103 100644 --- a/performance-comparison/benches/two_threads_with_chunks.rs +++ b/performance-comparison/benches/chunks.rs @@ -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; @@ -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| { diff --git a/performance-comparison/benches/two_threads_const.rs b/performance-comparison/benches/const_push_pop.rs similarity index 83% rename from performance-comparison/benches/two_threads_const.rs rename to performance-comparison/benches/const_push_pop.rs index 8eb212c2..cbc053f8 100644 --- a/performance-comparison/benches/two_threads_const.rs +++ b/performance-comparison/benches/const_push_pop.rs @@ -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) diff --git a/performance-comparison/benches/two_threads.rs b/performance-comparison/benches/push_pop.rs similarity index 93% rename from performance-comparison/benches/two_threads.rs rename to performance-comparison/benches/push_pop.rs index 0349935f..6c8fa64b 100644 --- a/performance-comparison/benches/two_threads.rs +++ b/performance-comparison/benches/push_pop.rs @@ -1,6 +1,6 @@ -#[path = "../../benches/two_threads.rs"] +#[path = "../../benches/push_pop.rs"] #[macro_use] -mod two_threads; +mod push_pop; use core::num::NonZeroUsize; @@ -8,7 +8,7 @@ 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(),