From the course: Python: Programming Efficiently

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Memory profiling

Memory profiling - Python Tutorial

From the course: Python: Programming Efficiently

Start my 1-month free trial

Memory profiling

- Just as we can profile CPU usage, we can do the same for the other crucial computing resource memory. Unfortunately in Python memory profiling is both harder and less precise because the interpreter manages memory automatically and that's not always allocated or released in the way that we would expect. Nevertheless, we can get a good sense of what's happening and we can compliment profiling with a theoretical understand of how different Python objects may use very different amounts of memory to store the same data. Let's begin with a simple case of an array of a million floating point numbers. The simplest way to store them in Python is perhaps a list which we can make with a usual list comprehension. Alternatively, we can use a NumPy array. These two look similar but they're actually very different internally. Python lists are implemented using dynamic arrays, a set of pointers, stored consecutively in memory…

Contents