Benchmarking memory footprint of method

⚓ Rust    📅 2026-04-03    👤 surdeus    👁️ 2      

surdeus

So I want to inspect the memory footprint of cloning an object in a for loop, to be specific a git2::Commit. I'm building my own iterator function and in designing a wider aspect of the API I may need to clone the object. Is there a way to write a benchmark test to prove this to myself??

The obvious answer is it is 2*size_of(git2::Commit), but I want to be sure that throughout the iteration (via revwalk) that everything is de-allocated as it should be such that each iteration has a footprint of 2*size_of(git2::Commit) + misc and not N * (2*size_of(git2::Commit) + misc) at the end of the iteration, where N is the number of commits accessible via revwalk

Sorry if this isn't very clear, it is my first post, so I'm happy to clarify anything :slight_smile: I also realise that I'm effectively trying to prove that variable scoping is working during iteration, so this may be a "duh that's how rust works" moment :rofl:

3 posts - 2 participants

Read full topic

🏷️ Rust_feed