use std::path::Path; use std::fs::File; use std::io::{BufRead, BufReader}; use fqdn::FQDN; use std::time::{Instant, Duration}; use cpu_time::ProcessTime; use std::collections::{HashSet}; fn main() { // Create a path to the desired file let path = Path::new("/Users/xophe/Logiciels/TESS/Antidote/mudkeys"); // Open the path in read-only mode, returns `io::Result` let file = File::open(&path).unwrap(); let reader = BufReader::new(file); let mut fqdns = reader.lines() .filter_map(|l| l.ok()) .filter_map(|s| s.parse::().ok()) .filter(|s| s.depth() > 3) .collect::>(); println!("test file contains {} FQDN", fqdns.len()); let now = Instant::now(); let start = ProcessTime::try_now().expect("Getting process time failed"); let mut trie = HashSet::new(); trie.extend(fqdns.iter().step_by(3).cloned()); let cpu_time: Duration = start.try_elapsed().expect("Getting process time failed"); let elapsed = now.elapsed(); println!("time elapsed using for building the hashmap: real={:?}, cpu={:?}", elapsed, cpu_time); fqdns.iter_mut().for_each(|f| *f = f.parent().unwrap().into()); let mut count = 0; let now = Instant::now(); let start = ProcessTime::try_now().expect("Getting process time failed"); fqdns.iter() .for_each(|f| { if trie.contains(f) { count += 1; } else { } }); let cpu_time: Duration = start.try_elapsed().expect("Getting process time failed"); let elapsed = now.elapsed(); println!("found {} fqdn", count); println!("time elapsed using for building the hashmap: real={:?}, cpu={:?}", elapsed, cpu_time); }