1
#[cfg(feature = "compression")]
2
use bonsaidb::local::config::Compression;
3
use bonsaidb::{
4
    core::{connection::Connection, test_util::TestDirectory},
5
    local::{
6
        config::{Builder, StorageConfiguration},
7
        Database,
8
    },
9
};
10
use criterion::{measurement::WallTime, BenchmarkGroup, BenchmarkId};
11
use ubyte::ToByteUnit;
12

            
13
use crate::collections::ResizableDocument;
14

            
15
10
fn save_document(doc: &ResizableDocument, db: &Database) {
16
10
    db.collection::<ResizableDocument>().push(doc).unwrap();
17
10
}
18

            
19
#[cfg_attr(not(feature = "compression"), allow(unused_mut))]
20
5
pub(super) fn save_documents(group: &mut BenchmarkGroup<WallTime>, doc: &ResizableDocument) {
21
5
    let path = TestDirectory::new("benches-basics.bonsaidb");
22
5
    let mut configs = vec![("bonsaidb-local", StorageConfiguration::new(&path))];
23
5
    #[cfg(feature = "compression")]
24
5
    {
25
5
        configs.push((
26
5
            "bonsaidb-local+lz4",
27
5
            StorageConfiguration::new(&path).default_compression(Compression::Lz4),
28
5
        ))
29
    }
30
15
    for (label, config) in configs {
31
10
        group.bench_function(BenchmarkId::new(label, doc.data.len().bytes()), |b| {
32
10
            let db = Database::open::<ResizableDocument>(config.clone()).unwrap();
33
10
            b.iter(|| save_document(doc, &db));
34
10
        });
35
10
    }
36

            
37
    // TODO bench read performance
38
    // TODO bench read + write performance (with different numbers of readers/writers)
39
    // TODO (once supported) bench batch saving
40
5
}