Skip to content

Instantly share code, notes, and snippets.

@joshmarlow
Last active September 17, 2016 16:34
Show Gist options
  • Save joshmarlow/05b4a53ed7a5043a93cf0c65d1075a8a to your computer and use it in GitHub Desktop.
Save joshmarlow/05b4a53ed7a5043a93cf0c65d1075a8a to your computer and use it in GitHub Desktop.
time_it macro in Rust
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