Skip to content

Instantly share code, notes, and snippets.

@cowlicks
Last active April 10, 2022 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cowlicks/c793763d98c4457be7cd0d03644d2e82 to your computer and use it in GitHub Desktop.
Save cowlicks/c793763d98c4457be7cd0d03644d2e82 to your computer and use it in GitHub Desktop.
Rust. Simple macro for timing an expression
use log::info;
macro_rules! timeit {
($format_str:expr, $code:expr) => {
{
let start = Utc::now();
let out = $code;
info!(
$format_str,
(Utc::now() - start).num_milliseconds()
);
out
}
};
}
# usage
timeit(
"the thing took {} ms",
{
# the thing that takes time
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment