-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from insight-platform/benchmark
Add benchmark test for mpmc queue
- Loading branch information
Showing
2 changed files
with
49 additions
and
2 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 |
---|---|---|
@@ -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(); | ||
} |
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