Lines
100 %
Functions
Branches
use bonsaidb::core::connection::Connection;
use bonsaidb::core::test_util::TestDirectory;
#[cfg(feature = "compression")]
use bonsaidb::local::config::Compression;
use bonsaidb::local::config::{Builder, StorageConfiguration};
use bonsaidb::local::Database;
use criterion::measurement::WallTime;
use criterion::{BenchmarkGroup, BenchmarkId};
use ubyte::ToByteUnit;
use crate::collections::ResizableDocument;
fn save_document(doc: &ResizableDocument, db: &Database) {
db.collection::<ResizableDocument>().push(doc).unwrap();
}
#[cfg_attr(not(feature = "compression"), allow(unused_mut))]
pub(super) fn save_documents(group: &mut BenchmarkGroup<WallTime>, doc: &ResizableDocument) {
let path = TestDirectory::absolute("benches-basics.bonsaidb");
let mut configs = vec![("bonsaidb-local", StorageConfiguration::new(&path))];
{
configs.push((
"bonsaidb-local+lz4",
StorageConfiguration::new(&path).default_compression(Compression::Lz4),
))
for (label, config) in configs {
group.bench_function(BenchmarkId::new(label, doc.data.len().bytes()), |b| {
let db = Database::open::<ResizableDocument>(config.clone()).unwrap();
b.iter(|| save_document(doc, &db));
});
// TODO bench read performance
// TODO bench read + write performance (with different numbers of readers/writers)
// TODO (once supported) bench batch saving