Last active
January 7, 2023 07:22
-
-
Save matthewjberger/d6d2124ab51e460ae3e380bb1f26e5c3 to your computer and use it in GitHub Desktop.
A rust profiling macro
This file contains 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
// let (entities, duration) = profile!(world.create_entities(1_000_000)); | |
// println!("Creating 1 million entities completed in {:?}", duration); | |
// | |
// let results: Vec<(_, Duration)> = profile_n!(100, world.create_entities(1_000_000)); | |
#[macro_export] | |
macro_rules! profile { | |
($($actions:tt)*) => { | |
{ | |
let start = std::time::Instant::now(); | |
let result = $($actions)*; | |
let duration = start.elapsed(); | |
(result, duration) | |
} | |
} | |
} | |
#[macro_export] | |
macro_rules! profile_n { | |
($n:tt, $($actions:tt)*) => { | |
(0..$n).map(|_| { | |
profile!($($actions)*) | |
}) | |
.collect::<Vec<_>>() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment