pub fn index_path(
store: &mut Store,
root: &Path,
) -> Result<Stats, Box<dyn Error>>Expand description
Index the whole repository rooted at root.
Examples found in repository?
examples/bench.rs (line 33)
29fn main() {
30 let root = PathBuf::from(std::env::args().nth(1).unwrap_or_else(|| ".".into()));
31
32 let mut store = Store::open_in_memory().expect("open store");
33 let stats = index::index_path(&mut store, &root).expect("index");
34 println!(
35 "indexed {} symbols from {} file(s) under {}",
36 stats.symbols,
37 stats.files_indexed,
38 root.display()
39 );
40
41 // warm up
42 for q in QUERIES {
43 let _ = search::search(&store, q, None, None, &search::ActiveFiles::default(), 10);
44 }
45
46 let mut times_us: Vec<u128> = Vec::new();
47 for _ in 0..200 {
48 for q in QUERIES {
49 let start = Instant::now();
50 let _ = search::search(&store, q, None, None, &search::ActiveFiles::default(), 10)
51 .expect("search");
52 times_us.push(start.elapsed().as_micros());
53 }
54 }
55 times_us.sort_unstable();
56
57 let pct = |p: f64| times_us[((times_us.len() as f64 - 1.0) * p).round() as usize];
58 println!(
59 "search over {} runs: p50 {} µs p95 {} µs max {} µs",
60 times_us.len(),
61 pct(0.50),
62 pct(0.95),
63 times_us[times_us.len() - 1],
64 );
65 let budget_us = 50_000;
66 let over = times_us.iter().filter(|&&t| t > budget_us).count();
67 println!("{}/{} runs exceeded the 50 ms budget", over, times_us.len());
68}