1
use bonsaidb::core::{arc_bytes::serde::Bytes, schema::Collection};
2
use criterion::{Criterion, Throughput};
3
use rand::{thread_rng, Rng};
4
use serde::{Deserialize, Serialize};
5

            
6
mod bonsai;
7
#[cfg(feature = "sqlite")]
8
mod rusqlite;
9

            
10
100
#[derive(Serialize, Deserialize, Debug, Collection)]
11
#[collection(name = "resizable-docs")]
12
struct ResizableDocument {
13
    data: Bytes,
14
}
15

            
16
1
pub fn save_documents(c: &mut Criterion) {
17
1
    static KB: usize = 1024;
18
1

            
19
1
    // First set of benchmarks tests inserting documents
20
1
    let mut group = c.benchmark_group("save_documents");
21
5
    for size in [KB, 2 * KB, 8 * KB, 32 * KB, KB * KB] {
22
5
        let mut rng = thread_rng();
23
5
        group.throughput(Throughput::Bytes(size as u64));
24
1092608
        let mut data = (0..size).map(|_| rng.gen()).collect::<Vec<_>>();
25
5
        data.resize_with(size, || 7u8);
26
5
        let doc = ResizableDocument {
27
5
            data: Bytes::from(data),
28
5
        };
29
5

            
30
5
        bonsai::save_documents(&mut group, &doc);
31
5
        #[cfg(feature = "sqlite")]
32
5
        rusqlite::save_documents(&mut group, &doc);
33
5
    }
34
1
    group.finish();
35
1
}