Skip to content

Add performance comparison between crates #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2024
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Cargo.lock
/target/
target/
32 changes: 32 additions & 0 deletions performance-comparison/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
63 changes: 63 additions & 0 deletions performance-comparison/benches/two_threads.rs
Original file line number Diff line number Diff line change
@@ -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()

);
1 change: 1 addition & 0 deletions performance-comparison/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// empty
Loading