Files
aether-atom/examples/bench.rs
T

47 lines
1.3 KiB
Rust
Raw Normal View History

2026-07-09 13:28:19 -04:00
use aether_atom::*;
use aether_atom::fingerprint;
use std::time::Instant;
fn main() {
let dir = tempfile::tempdir().unwrap();
let mut lat = Lattice::open(dir.path()).unwrap();
let body: Vec<u8> = vec![0xAB; 1024];
let body_str = BodyAsStr(&body);
remember(&mut lat, "global", &body_str, body.clone(), Some(true));
let _ = ask(&mut lat, "global", &body_str, |_| body.clone());
let n = 10_000;
// 1) cached ask() ops — these include a per-call disk write
let t = Instant::now();
for _ in 0..n {
let _ = ask(&mut lat, "global", &body_str, |_| Vec::new());
}
let cached = t.elapsed();
println!(
"{n} cached ask() ops (incl. disk write): {cached:?} ({:.2} µs/op)",
cached.as_micros() as f64 / n as f64
);
let n_lookups = 100_000;
let sig = fingerprint(&body);
// 2) raw lookup() — also writes per call
let t = Instant::now();
for _ in 0..n_lookups {
let _ = lat.lookup(&sig, "global");
}
println!(
"{n_lookups} raw lookup() ops: {:?} ({:.2} µs/op)",
t.elapsed(),
t.elapsed().as_micros() as f64 / n_lookups as f64
);
}
struct BodyAsStr<'a>(&'a [u8]);
impl Canonicalize for BodyAsStr<'_> {
fn canonical(&self) -> Vec<u8> {
self.0.to_vec()
}
}