You can ask how long a function took with one line of timing code. Asking how much memory it used is harder, and this project makes it as easy. It builds a context manager and a decorator on top of tracemalloc that report the peak memory of a block, the memory that it left behind, and the line that allocated the most, and uses them to show, with numbers, that a generator uses far less memory than a list.
More lessons in Complete Python Programming