Skip to main content

Module alloc

Module alloc 

Source
Available on crate feature alloc-tracking only.
Expand description

Allocation tracking. Available with the alloc-tracking feature.

Wraps dhat to capture total bytes, total allocation count, and peak resident bytes during a benchmark. Reports a CheckResult with regression-style verdict.

§Cost

Enabling alloc-tracking installs dhat::Alloc as the global allocator. This is heavier than the default allocator and materially changes timing characteristics. Do not combine allocation thresholds with timing thresholds in the same invocation. Run timing benchmarks with the feature off and allocation benchmarks with it on.

§Setup

At the top of your binary or test target:

#[cfg(feature = "alloc-tracking")]
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;

Then start a profiler before the benchmark and snapshot stats after:

let _profiler = dhat::Profiler::new_heap();
// ... run benchmarked code ...
let stats = dev_bench::alloc::AllocationStats::snapshot();

Structs§

AllocationStats
Snapshot of allocation activity, captured from dhat::HeapStats.