File: cdb.rs

package info (click to toggle)
rust-cdb 0.6.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 248 kB
  • sloc: makefile: 10; sh: 9
file content (49 lines) | stat: -rw-r--r-- 1,471 bytes parent folder | download
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);