mod parser; mod stats; mod trie; use stats::Stats; use std::{env, fs, sync::LazyLock}; use tokio::sync::mpsc; use trie::Trie; static FORBIDDEN_WORDS: LazyLock = LazyLock::new(|| { let mut trie = Trie::default(); for word in [ "recovery", "techie", "http", "https", "digital", "hack", "::", "//", "@", "com", "crypto", "bitcoin", "wallet", "hacker", "welcome", "whatsapp", "email", "cryptocurrency", "stolen", "freeze", "quick", "crucial", "tracing", "scammers", "expers", "hire", "century", "transaction", "essential", "managing", "contact", "contacting", "understanding", "assets", "funds", ] { trie.insert(word); } trie }); #[tokio::main] async fn main() { let files = env::args().skip(1); let mut stats = Stats::default(); let mut rx = { let (tx, rx) = mpsc::unbounded_channel(); for file in files { //reading files not sequentially average shaves 30ms (of 1250ms), and that's on a NVMe SSD so why not if let Ok(text) = fs::read_to_string(&file) { stats.file_count += 1; let tx = tx.clone(); tokio::spawn(async move { let mut stats = Stats::default(); parser::for_loops::parse(&mut stats, &text); let _ = tx.send(stats); }); } else { stats.failed_file_count += 1; } } rx }; while let Some(file_stat) = rx.recv().await { stats += file_stat; } println!("{stats}"); } /// needs ../books.tar.gz to be extracted #[test] fn test() { use std::{env, fs, process::Command, time::Instant}; println!("cwd: {}", env::current_dir().unwrap().display()); //compile let mut compile = Command::new("cargo"); let compile_arged = compile.arg("build").arg("--release"); match compile_arged.output() { Ok(output) => println!("compiled {}", String::from_utf8_lossy(&output.stdout)), Err(err) => eprintln!("compile failed: {err}"), } //get test files let files = fs::read_dir("../books") .unwrap() .map(|f| { f.unwrap() .path() .canonicalize() .unwrap() .to_str() .unwrap() .to_string() }) .collect::>(); println!("test files found: {}", files.len()); println!(); //benchmark run let benchmark = Instant::now(); let mut run = Command::new("target/release/jisspam"); let run_arged = run.args(files); match run_arged.output() { Ok(output) => println!("{}", String::from_utf8_lossy(&output.stdout)), Err(err) => eprintln!("run failed: {err}"), } println!("benchmark: {}ms", benchmark.elapsed().as_millis()); }