//! Index timing on a generated 20,000-file project. Ignored by default; run //! `cargo test --release -p lutra-index --test perf -- --ignored --nocapture`. #![allow( clippy::unwrap_used, clippy::expect_used, clippy::indexing_slicing, clippy::panic )] use std::time::Instant; use lutra_index::{CancelToken, Index, Update, build, default_threads}; #[test] #[ignore = "measurement; run in release"] fn index_20k_files() { let dir = tempfile::tempdir().unwrap(); let project = lutra_testkit::generate_php_project(dir.path(), 20_000); println!( "generated: {} indexed files, {} PHP ({} vendor), {:.1} MB PHP, {} classes", project.indexed_files, project.php_files, project.vendor_files, project.php_bytes as f64 / 1e6, project.classes ); let threads = default_threads(); for round in 0..3 { let index = std::sync::Mutex::new(Index::new()); let mut first_batch = None; let started = Instant::now(); let first = std::sync::Mutex::new(&mut first_batch); let summary = build(dir.path(), threads, &CancelToken::new(), &|u| { if let Update::Files { files, .. } = u { let mut first = first.lock().unwrap(); if first.is_none() { **first = Some(started.elapsed()); } let mut index = index.lock().unwrap(); for f in files { index.insert(f); } } }); let index = index.into_inner().unwrap(); assert_eq!(index.len(), project.indexed_files); let time = |f: &dyn Fn() -> usize| { let mut runs: Vec = (0..7) .map(|_| { let t = Instant::now(); assert!(f() > 0); t.elapsed().as_secs_f64() * 1e3 }) .collect(); runs.sort_by(f64::total_cmp); (runs[0], runs[3]) }; let class = time(&|| index.find_classes("Serv12", 50).len()); let symbol = time(&|| index.find_symbols("handle1", 50).len()); let member = time(&|| index.find_symbols("Service12::hand", 50).len()); let file = time(&|| index.find_files("wid12", 50).len()); println!( "round {round}: {threads} workers, walk {:.0} ms, first batch {:.0} ms, total {:.0} ms, {} files, {} symbols, {} parsed ({:.1} MB)", summary.walk.as_secs_f64() * 1e3, first_batch.unwrap().as_secs_f64() * 1e3, summary.elapsed.as_secs_f64() * 1e3, summary.files, summary.symbols, summary.parsed, summary.parsed_bytes as f64 / 1e6, ); println!( " queries (min / median of 7): goto.class {:.1} / {:.1} ms, goto.symbol {:.1} / {:.1} ms, Class::member {:.1} / {:.1} ms, goto.file {:.1} / {:.1} ms", class.0, class.1, symbol.0, symbol.1, member.0, member.1, file.0, file.1 ); } }