1
use bonsaidb::{
2
    core::{connection::Connection, test_util::TestDirectory},
3
    local::{
4
        config::{Builder, StorageConfiguration},
5
        Database,
6
    },
7
};
8
use criterion::{measurement::WallTime, BenchmarkGroup, BenchmarkId};
9
use ubyte::ToByteUnit;
10

            
11
use crate::collections::ResizableDocument;
12

            
13
5
async fn save_document(doc: &ResizableDocument, db: &Database) {
14
5
    db.collection::<ResizableDocument>()
15
5
        .push(doc)
16
5
        .await
17
5
        .unwrap();
18
5
}
19

            
20
5
pub(super) fn save_documents(group: &mut BenchmarkGroup<WallTime>, doc: &ResizableDocument) {
21
5
    group.bench_function(
22
5
        BenchmarkId::new("bonsaidb-local", doc.data.len().bytes()),
23
5
        |b| {
24
5
            let runtime = tokio::runtime::Runtime::new().unwrap();
25
5
            let path = TestDirectory::new("benches-basics.bonsaidb");
26
5
            let db = runtime
27
5
                .block_on(Database::open::<ResizableDocument>(
28
5
                    StorageConfiguration::new(&path),
29
5
                ))
30
5
                .unwrap();
31
5
            b.to_async(&runtime).iter(|| save_document(doc, &db));
32
5
        },
33
5
    );
34
5

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