Last active
April 10, 2022 22:22
-
-
Save cowlicks/c793763d98c4457be7cd0d03644d2e82 to your computer and use it in GitHub Desktop.
Rust. Simple macro for timing an expression
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
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