pub fn measure<F: FnOnce()>(run_while_measuring: F) -> AllocationInfo
Expand description
Run a closure or function while measuring the performed memory allocations.
Will only measure those allocations done by the current thread, so take care when interpreting the returned count for multithreaded code.
Use opt_out() to opt of of counting allocations temporarily.
Nested measure()
calls are supported up to a max depth of 64.
§Arguments
run_while_measuring
- The code to run while measuring allocations
§Examples
let actual = allocation_counter::measure(|| {
"hello, world".to_string();
});
let expected = allocation_counter::AllocationInfo {
count_total: 1,
count_current: 0,
count_max: 1,
bytes_total: 12,
bytes_current: 0,
bytes_max: 12,
};
assert_eq!(actual, expected);