1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
extern crate cdb;
#[macro_use]
extern crate criterion;
use cdb::CDB;
use criterion::Criterion;
fn test_cdb() -> CDB {
CDB::open("tests/test2.cdb").expect("Could not open tests/test2.cdb")
}
fn reader_benchmark(c: &mut Criterion) {
c.bench_function("CDB::open", |b| b.iter(|| { test_cdb(); }));
c.bench_function("CDB::find", |b| {
let cdb = test_cdb();
b.iter(|| cdb.find(b"two"))
});
c.bench_function("CDB::find long", |b| {
let cdb = test_cdb();
b.iter(|| cdb.find(b"this key will be split across two reads"))
});
c.bench_function("CDB::find result", |b| {
let cdb = test_cdb();
b.iter(|| cdb.find(b"two").next().unwrap())
});
c.bench_function("CDB::find result loop", |b| {
let cdb = test_cdb();
b.iter(|| for result in cdb.find(b"one") { result.unwrap(); })
});
c.bench_function("CDB::open + find result loop", |b| b.iter(|| {
let cdb = test_cdb();
for result in cdb.find(b"one") {
result.unwrap();
}
}));
c.bench_function("CDB::iter result loop", |b| {
let cdb = test_cdb();
b.iter(|| for result in cdb.iter() { result.unwrap(); })
});
c.bench_function("CDB::open + iter result loop", |b| b.iter(|| {
let cdb = test_cdb();
for result in cdb.iter() {
result.unwrap();
}
}));
}
criterion_group!(benches, reader_benchmark);
criterion_main!(benches);
|