-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add performance comparison between crates
- Loading branch information
Showing
5 changed files
with
128 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
Cargo.lock | ||
/target/ | ||
target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#[path = "../../benches/two_threads.rs"] | ||
mod two_threads; | ||
|
||
use two_threads::add_function; | ||
|
||
use criterion::{criterion_group, criterion_main}; | ||
|
||
fn criterion_benchmark(criterion: &mut criterion::Criterion) { | ||
let mut group = criterion.benchmark_group("two-threads"); | ||
|
||
add_function( | ||
&mut group, | ||
"-0-npnc", | ||
|capacity| npnc::bounded::spsc::channel(capacity.next_power_of_two()), | ||
|p, i| p.produce(i).is_ok(), | ||
|c| c.consume().ok(), | ||
); | ||
|
||
add_function( | ||
&mut group, | ||
"-1-rtrb", | ||
rtrb::RingBuffer::new, | ||
|p, i| p.push(i).is_ok(), | ||
|c| c.pop().ok(), | ||
); | ||
|
||
add_function( | ||
&mut group, | ||
"-1-crossbeam-queue-pr338", | ||
crossbeam_queue_pr338::spsc::new, | ||
|q, i| q.push(i).is_ok(), | ||
|q| q.pop().ok(), | ||
); | ||
|
||
use magnetic::{Consumer, Producer}; | ||
|
||
add_function( | ||
&mut group, | ||
"-2-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(), | ||
); | ||
|
||
add_function( | ||
&mut group, | ||
"-2-omango", | ||
|capacity| omango::queue::spsc::bounded(u32::try_from(capacity).unwrap()), | ||
|p, i| p.try_send(i).is_ok(), | ||
|c| c.try_recv().ok(), | ||
); | ||
|
||
use ringbuf::traits::Split as _; | ||
use ringbuf::traits::Producer as _; | ||
use ringbuf::traits::Consumer as _; | ||
|
||
add_function( | ||
&mut group, | ||
"-2-ringbuf", | ||
|capacity| ringbuf::HeapRb::new(capacity).split(), | ||
|p, i| p.try_push(i).is_ok(), | ||
|c| c.try_pop(), | ||
); | ||
|
||
add_function( | ||
&mut group, | ||
"-3-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(), | ||
); | ||
|
||
add_function( | ||
&mut group, | ||
"-3-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(), | ||
); | ||
|
||
group.finish(); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// empty |