From 4865c87f9bd6d1d7f7c312cb58f2b315b24df965 Mon Sep 17 00:00:00 2001 From: Matthias Geier Date: Mon, 29 Apr 2024 21:36:33 +0200 Subject: [PATCH] Add performance comparison between crates --- .gitignore | 2 +- performance-comparison/Cargo.toml | 32 ++++++++++ performance-comparison/benches/two_threads.rs | 63 +++++++++++++++++++ performance-comparison/src/lib.rs | 1 + 4 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 performance-comparison/Cargo.toml create mode 100644 performance-comparison/benches/two_threads.rs create mode 100644 performance-comparison/src/lib.rs diff --git a/.gitignore b/.gitignore index 80faede..1e7caa9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ Cargo.lock -/target/ +target/ diff --git a/performance-comparison/Cargo.toml b/performance-comparison/Cargo.toml new file mode 100644 index 0000000..4d14434 --- /dev/null +++ b/performance-comparison/Cargo.toml @@ -0,0 +1,32 @@ +[package] +name = "ringbuffer-performance-comparison" +version = "0.0.0" +edition = "2021" + +publish = false + +[dependencies] +concurrent-queue = "2.3" +crossbeam-queue = "0.3" +crossbeam-queue-pr338 = { git = "https://github.com/mgeier/crossbeam", branch = "spsc", package = "crossbeam-queue" } +magnetic = "2" +npnc = "0.2" +omango = "0.2" +ringbuf = "0.4" +rtrb = { path = ".." } + +[dev-dependencies] +criterion = "0.5" + +# aggressive optimization for benchmarks +[profile.bench] +lto = true +opt-level = 3 +codegen-units = 1 + +[lib] +bench = false # Don't disturb criterion command line parsing + +[[bench]] +name = "two_threads" +harness = false diff --git a/performance-comparison/benches/two_threads.rs b/performance-comparison/benches/two_threads.rs new file mode 100644 index 0000000..1480f81 --- /dev/null +++ b/performance-comparison/benches/two_threads.rs @@ -0,0 +1,63 @@ +#[path = "../../benches/two_threads.rs"] +#[macro_use] +mod two_threads; + +use magnetic::Consumer as _; +use magnetic::Producer as _; + +use ringbuf::traits::Consumer as _; +use ringbuf::traits::Producer as _; +use ringbuf::traits::Split as _; + +create_two_threads_benchmark!( + + "1-npnc", + |capacity| npnc::bounded::spsc::channel(capacity.next_power_of_two()), + |p, i| p.produce(i).is_ok(), + |c| c.consume().ok(); + + "2-crossbeam-queue-pr338", + crossbeam_queue_pr338::spsc::new, + |q, i| q.push(i).is_ok(), + |q| q.pop().ok(); + + "3-rtrb", + rtrb::RingBuffer::new, + |p, i| p.push(i).is_ok(), + |c| c.pop().ok(); + + "4-omango", + |capacity| omango::queue::spsc::bounded(u32::try_from(capacity).unwrap()), + |p, i| p.try_send(i).is_ok(), + |c| c.try_recv().ok(); + + "5-ringbuf", + |capacity| ringbuf::HeapRb::new(capacity).split(), + |p, i| p.try_push(i).is_ok(), + |c| c.try_pop(); + + "6-magnetic", + |capacity| { + let buffer = magnetic::buffer::dynamic::DynamicBuffer::new(capacity).unwrap(); + magnetic::spsc::spsc_queue(buffer) + }, + |p, i| p.try_push(i).is_ok(), + |c| c.try_pop().ok(); + + "7-concurrent-queue", + |capacity| { + let q = std::sync::Arc::new(concurrent_queue::ConcurrentQueue::bounded(capacity)); + (q.clone(), q) + }, + |q, i| q.push(i).is_ok(), + |q| q.pop().ok(); + + "8-crossbeam-queue", + |capacity| { + let q = std::sync::Arc::new(crossbeam_queue::ArrayQueue::new(capacity)); + (q.clone(), q) + }, + |q, i| q.push(i).is_ok(), + |q| q.pop() + +); diff --git a/performance-comparison/src/lib.rs b/performance-comparison/src/lib.rs new file mode 100644 index 0000000..8b1a393 --- /dev/null +++ b/performance-comparison/src/lib.rs @@ -0,0 +1 @@ +// empty