How to calculate memory usage?

Hello !

I am working on a comparison between Rust and C and I would like to compare the memory usage of both algorithms. I think that Rust consumes less memory than C because of the use of iterators, but my question is, which tool is useful to calculate the memory usage ?

Thank you !!

What OS?

On Linux !

If you compile the executable with cargo build --release, you will find the binary at ./target/release/your_package_name. You can then try

/usr/bin/time -v ./target/release/your_package_name

Then look for the line with "Maximum resident set size".

See this question for more info.

1 Like

Thanks ! And this works with parallel programs or only with serial programs ?

Should work in parallel too.

1 Like

If you want to know byte-exact amount of memory allocated by Rust itself, you can instrument Rust's memory allocator. For example, there's cap. But for comparison with C, an external measurement will be more fair.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.