#![allow(dead_code)] use fqdn_trie::*; use std::io::{BufReader, BufRead}; use std::fs::File; use std::collections::HashSet; use std::time::{Instant, Duration}; use cpu_time::ProcessTime; use fqdn::FQDN; fn main() { let alexa = BufReader::new( File::open("/Users/xophe/florent/threatnet/data/DGA/20190920_alexa-top.txt").expect("can’t open file")) .lines() .map(|x| (x.expect("illegal char")+".").parse::().expect("parse error")) .collect::>(); let _tests = BufReader::new( File::open("/Users/xophe/Logiciels/TESS/Antidote/test-alexa.txt").expect("can’t open file")) .lines() .map(|x| (x.expect("illegal char")).parse::()) .filter_map(|y| y.ok()) .collect::>(); let now = Instant::now(); let start = ProcessTime::try_now().expect("Getting process time failed"); let _alexa = alexa.iter().cloned().collect::>(); //let alexa = alexa.iter().cloned().collect::>(); let cpu_time: Duration = start.try_elapsed().expect("Getting process time failed"); let elapsed = now.elapsed(); eprintln!("building time: real={:?}, cpu={:?}", elapsed, cpu_time); /* let now2 = Instant::now(); let start2 = ProcessTime::try_now().expect("Getting process time failed"); let count = trie_lookup(alexa, &tests); //let count = hash_lookup(alexa, &tests); let cpu_time2: Duration = start2.try_elapsed().expect("Getting process time failed"); let elapsed2 = now2.elapsed(); let cpu_time: Duration = start.try_elapsed().expect("Getting process time failed"); let elapsed = now.elapsed(); eprintln!("lookup matches: {} / {}", count, tests.len()); eprintln!("lookup time: real={:?}, cpu={:?}", elapsed2, cpu_time2); eprintln!("total time: real={:?}, cpu={:?}", elapsed, cpu_time);*/ std::thread::sleep(Duration::from_secs(5)); } fn trie_lookup(trie: FqdnTrieSet, tests: &Vec) -> usize { tests.iter().filter(|f| !trie.lookup(*f).is_root() ).count() } fn hash_lookup(set: HashSet, tests: &Vec) -> usize { tests.iter() .filter(|f| f.hierarchy().any(|f| set.contains(f))) .count() }