2022-12-11 19:42:52 +00:00
|
|
|
use client::database::Database;
|
2023-01-31 23:23:55 +00:00
|
|
|
use config::Config;
|
2022-12-11 19:42:52 +00:00
|
|
|
use criterion::{criterion_group, criterion_main, Criterion};
|
|
|
|
use helios::prelude::FileDB;
|
|
|
|
use tempfile::tempdir;
|
|
|
|
|
|
|
|
mod harness;
|
|
|
|
|
|
|
|
criterion_main!(file_db);
|
|
|
|
criterion_group! {
|
|
|
|
name = file_db;
|
|
|
|
config = Criterion::default();
|
|
|
|
targets = save_checkpoint, load_checkpoint
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Benchmark saving/writing a checkpoint to the file db.
|
|
|
|
pub fn save_checkpoint(c: &mut Criterion) {
|
|
|
|
c.bench_function("save_checkpoint", |b| {
|
|
|
|
let checkpoint = vec![1, 2, 3];
|
|
|
|
b.iter(|| {
|
2023-01-31 23:23:55 +00:00
|
|
|
let data_dir = Some(tempdir().unwrap().into_path());
|
|
|
|
let config = Config {
|
|
|
|
data_dir,
|
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
let db = FileDB::new(&config).unwrap();
|
2022-12-11 19:42:52 +00:00
|
|
|
db.save_checkpoint(checkpoint.clone()).unwrap();
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Benchmark loading a checkpoint from the file db.
|
|
|
|
pub fn load_checkpoint(c: &mut Criterion) {
|
|
|
|
c.bench_function("load_checkpoint", |b| {
|
|
|
|
// First write to the db
|
2023-01-31 23:23:55 +00:00
|
|
|
let data_dir = Some(tempdir().unwrap().into_path());
|
|
|
|
let config = Config {
|
|
|
|
data_dir,
|
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
let db = FileDB::new(&config).unwrap();
|
|
|
|
let written_checkpoint = vec![1; 32];
|
2022-12-11 19:42:52 +00:00
|
|
|
db.save_checkpoint(written_checkpoint.clone()).unwrap();
|
|
|
|
|
|
|
|
// Then read from the db
|
|
|
|
b.iter(|| {
|
|
|
|
let checkpoint = db.load_checkpoint().unwrap();
|
|
|
|
assert_eq!(checkpoint, written_checkpoint.clone());
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|