Function allocation_counter::count

source ·
pub fn count<F: FnOnce()>(run_while_counting: F) -> u64
Expand description

Run a closure while counting the performed memory allocations.

Will only measure those done by the current thread, so take care when interpreting the returned count for multithreaded programs.

Arguments

  • run_while_counting - The code to run while counting allocations

Examples

let allocations = allocation_counter::count(|| {
     "hello, world".to_string();
});
assert_eq!(allocations, 1);