//! Criterion bench for mmap-strategy wins (waves 1-3). //! //! Measures the per-tensor-hint application time + the //! end-to-end load time under different PrefetchPolicy //! variants. Page-cache state is not controlled (no easy //! way to evict from userspace); for cold-cache TTFT //! numbers, run on a freshly-booted box or use `drop_caches` //! between iterations. use std::hint::black_box; use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; use jouleclaw_loader_gguf::synthetic::{synthesize_llama_gguf, SyntheticConfig}; use jouleclaw_loader_gguf::{ read_gguf_file, read_gguf_file_with_policy, PrefetchPolicy, }; use std::io::Write; use std::path::PathBuf; fn write_synth_gguf(tag: &str) -> PathBuf { let bytes = synthesize_llama_gguf(&SyntheticConfig::default()); let dir = std::env::temp_dir(); let pid = std::process::id(); let path = dir.join(format!("jouleclaw-bench-{}-{}.gguf", tag, pid)); let mut f = std::fs::File::create(&path).unwrap(); f.write_all(&bytes).unwrap(); f.sync_all().unwrap(); path } fn bench_policies(c: &mut Criterion) { let path = write_synth_gguf("policies"); let mut g = c.benchmark_group("read_gguf_file_with_policy"); let policies = [ ("none", PrefetchPolicy::None), ("all", PrefetchPolicy::All), ("per_tensor_only", PrefetchPolicy::PerTensorOnly), ("top_n_3", PrefetchPolicy::TopN(3)), ("top_n_10", PrefetchPolicy::TopN(10)), ]; for (label, policy) in policies { g.bench_with_input( BenchmarkId::from_parameter(label), &policy, |b, &policy| { b.iter(|| { let m = read_gguf_file_with_policy(black_box(&path), policy) .expect("parse"); black_box(&m); }); }, ); } g.finish(); // Default-API path baseline. c.bench_function("read_gguf_file_default", |b| { b.iter(|| { let m = read_gguf_file(black_box(&path)).expect("parse"); black_box(&m); }); }); let _ = std::fs::remove_file(path); } criterion_group!(benches, bench_policies); criterion_main!(benches);