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

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

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

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

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

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