An open API service indexing awesome lists of open source software.

https://github.com/pseitz/peakmem-alloc

Measure the peak memory consumption of a given scope in rust
https://github.com/pseitz/peakmem-alloc

Last synced: about 1 year ago
JSON representation

Measure the peak memory consumption of a given scope in rust

Awesome Lists containing this project

README

          

# peakmem_alloc

An instrumenting middleware for global allocators in Rust, useful to find the peak memory consumed by a function.

## Example

```rust
use peakmem_alloc::*;
use std::alloc::System;

#[global_allocator]
static GLOBAL: &PeakMemAlloc = &INSTRUMENTED_SYSTEM;

#[test]
fn example_using_region() {
GLOBAL.reset_peak_memory(); // Note that other threads may impact the peak memory computation.
let _x: Vec = Vec::with_capacity(1_024);
println!(
"Peak Memory used by function : {:#?}",
GLOBAL.get_peak_memory()
);
}

```

## Custom allocators

You can wrap your existing allocator as follows:

```rust
use jemallocator::Jemalloc;
use peakmem_alloc::*;

#[global_allocator]
static GLOBAL: PeakMemAlloc = PeakMemAlloc::new(Jemalloc);

```