How do I profile memory usage in Python?

I’ve recently become interested in algorithms and have begun exploring them by writing a naive implementation and then optimizing it in various ways.

I’m already familiar with the standard Python module for profiling runtime (for most things I’ve found the timeit magic function in IPython to be sufficient), but I’m also interested in memory usage so I can explore those tradeoffs as well (e.g. the cost of caching a table of previously computed values versus recomputing them as needed). Is there a module that will profile the memory usage of a given function for me?

8 Answers
8

Leave a Comment