use core_api::{GraphDb, OpenOptions};
use std::time::Instant;
fn main() {
let n: usize = std::env::var("REFRESH_BENCH_N")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(20_000);
let refreshes: usize = 40;
let dir = std::env::temp_dir().join("mdb-refresh-bench");
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
let mut w = GraphDb::open(&dir).unwrap();
println!("seeding {n} nodes...");
for i in 0..n {
w.insert_node("N", &format!("n{i}"), vec![]).unwrap();
}
w.snapshot().unwrap();
let mut r = GraphDb::open_with_options(
&dir,
OpenOptions {
read_only: true,
..Default::default()
},
)
.unwrap();
let _ = r.refresh().unwrap();
let mut total = std::time::Duration::ZERO;
for i in 0..refreshes {
w.insert_node("N", &format!("peer{i}"), vec![]).unwrap();
let t = Instant::now();
let applied = r.refresh().unwrap();
total += t.elapsed();
assert!(
applied >= 1,
"refresh {i} applied nothing — the bench is wrong"
);
}
println!(
"{refreshes} refreshes, each applying >=1 peer commit and folding: \
{total:?} total, {:?}/refresh",
total / refreshes as u32
);
}