use rust_meth_lib::analyzer::{find_rust_analyzer, query_methods};
use rust_meth_lib::results_cache::results_cache_entries;
use std::time::Instant;
fn main() -> rust_meth_lib::error::Result<()> {
let ra_path = find_rust_analyzer()?;
println!("First call (cold cache)...");
let t1 = Instant::now();
let methods = query_methods("Vec<u8>", &ra_path, None)?;
let elapsed1 = t1.elapsed();
println!(" {} methods found in {:.2?}\n", methods.len(), elapsed1);
let entries = results_cache_entries();
println!("Results cache now has {} entry:", entries.len());
for e in &entries {
println!(
" {} : {} methods (ra: {})",
e.type_name, e.method_count, e.ra_version
);
}
println!();
println!("Second call (warm cache)...");
let t2 = Instant::now();
let methods2 = query_methods("Vec<u8>", &ra_path, None)?;
let elapsed2 = t2.elapsed();
println!(" {} methods found in {:.2?}\n", methods2.len(), elapsed2);
let speedup = elapsed1.as_secs_f64() / elapsed2.as_secs_f64();
println!("Speedup: {speedup:.0}x faster on cache hit");
println!("\nRun this example again to see the persistent cache kick in");
println!(
"on the very first call (~0ms instead of ~{}s).",
elapsed1.as_secs()
);
Ok(())
}