[][src]Function alloc_counter::count_alloc

pub fn count_alloc<F, R>(f: F) -> (Counters, R) where
    F: FnOnce() -> R, 

Count the allocations, reallocations, and deallocations that happen during execution of a closure.

Example:

let (counts, result) = count_alloc(|| {
    // no alloc
    let mut v = Vec::new();
    // alloc
    v.push(0);
    // realloc
    v.push(8);
    // return 8 from the closure
    v.pop().unwrap()
    // dealloc on dropping v
});
assert_eq!(result, 8);
assert_eq!(counts, (1, 1, 1));