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