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

            
11
use crate::collections::ResizableDocument;
12

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

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

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