Last active
September 17, 2016 16:34
-
-
Save joshmarlow/05b4a53ed7a5043a93cf0c65d1075a8a to your computer and use it in GitHub Desktop.
time_it macro in Rust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro_rules! time_it { | |
($msg:expr, $code:block) => ({ | |
let start = SystemTime::now(); | |
let res = { $code }; | |
let end = SystemTime::now(); | |
println!("{:?} duration: {:?}", $msg, end.duration_since(start).ok().unwrap()); | |
res | |
}) | |
} | |
... | |
time_it!(format!("Iteration: {}", _idx), { | |
let new_matches = Match::coalesce(&inputs, | |
templates, | |
references, | |
&excluded_datums, | |
n, | |
results, | |
s_distance, | |
strategy); | |
if new_matches.is_empty() { | |
return found_matches; | |
} else { | |
for m in new_matches.iter() { | |
if !excluded_datums.contains(&m.output) { | |
excluded_datums.insert(m.output.clone()); | |
inputs.push(m.clone()); | |
found_matches.push(m.clone()) | |
} | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment