Categories
Python Answers

How to profile memory usage in Python?

Spread the love

Sometimes, we want to profile memory usage in Python.

In this article, we’ll look at how to profile memory usage in Python.

How to profile memory usage in Python?

To profile memory usage in Python, we can use the guppy module.

To install it, we run

pip install guppy3

Then we use it by writing

from guppy import hpy

h = hpy()
print(h.heap())

to call heap to return a string with the list of items using memory.

All memory sizes are in bytes.

Conclusion

To profile memory usage in Python, we can use the guppy module.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *