Skip to content

Commit

Permalink
Merge pull request #8 from insight-platform/benchmark
Browse files Browse the repository at this point in the history
Add benchmark test for mpmc queue
  • Loading branch information
ksenia-vazhdaeva authored Aug 26, 2024
2 parents 2351d6c + 505f1d1 commit 03fa566
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
47 changes: 47 additions & 0 deletions queue_rs/benches/throughput_mpmc_sync.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#![feature(test)]

extern crate test;

use queue_rs::blocking::MpmcQueue;
use queue_rs::mpmc::StartPosition;
use std::time::Duration;
use test::Bencher;

const COUNT: usize = 10;
const LABEL: &str = "label";

#[bench]
fn rw_mixed(b: &mut Bencher) {
let block = vec![0u8; 256 * 1024];
let path = "/tmp/test_mpmc_b1".to_string();
_ = MpmcQueue::remove_db(&path);
{
let db = MpmcQueue::new(&path, Duration::from_secs(60)).unwrap();
b.iter(|| {
for _ in 0..COUNT {
db.add(&[&block]).unwrap();
db.next(1, LABEL, StartPosition::Oldest).unwrap();
}
});
}
MpmcQueue::remove_db(&path).unwrap();
}

#[bench]
fn write_read(b: &mut Bencher) {
let block = vec![0u8; 256 * 1024];
let path = "/tmp/test_mpmc_b2".to_string();
_ = MpmcQueue::remove_db(&path);
{
let db = MpmcQueue::new(&path, Duration::from_secs(60)).unwrap();
b.iter(|| {
for _ in 0..COUNT {
db.add(&[&block]).unwrap();
}
for _ in 0..COUNT {
db.next(1, LABEL, StartPosition::Oldest).unwrap();
}
});
}
MpmcQueue::remove_db(&path).unwrap();
}
4 changes: 2 additions & 2 deletions queue_rs/benches/throughput_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn rw_mixed(b: &mut Bencher) {
let path = "/tmp/test_b1".to_string();
_ = PersistentQueueWithCapacity::remove_db(&path);
{
let mut db = PersistentQueueWithCapacity::new(&path, COUNT, Options::default()).unwrap();
let db = PersistentQueueWithCapacity::new(&path, COUNT, Options::default()).unwrap();
b.iter(|| {
for _ in 0..COUNT {
db.push(&[&block]).unwrap();
Expand All @@ -31,7 +31,7 @@ fn write_read(b: &mut Bencher) {
let path = "/tmp/test_b2".to_string();
_ = PersistentQueueWithCapacity::remove_db(&path);
{
let mut db = PersistentQueueWithCapacity::new(&path, COUNT, Options::default()).unwrap();
let db = PersistentQueueWithCapacity::new(&path, COUNT, Options::default()).unwrap();
b.iter(|| {
for _ in 0..COUNT {
db.push(&[&block]).unwrap();
Expand Down

0 comments on commit 03fa566

Please sign in to comment.