views:

133

answers:

3

I have a program that contains a large number of objects, many of them Numpy arrays. My program is swapping miserably, and I'm trying to reduce the memory usage, because it actually can't finis on my system with the current memory requirements.

I am looking for a nice profiler that would allow me to check the amount of memory consumed by various objects (I'm envisioning a memory counterpart to cProfile) so that I know where to optimize.

I've heard decent things about Heapy, but Heapy unfortunately does not support Numpy arrays, and most of my program involves Numpy arrays.

A: 

Can you just save/pickle some of the arrays to disk in tmp files when not using them? That's what I've had to do in the past with large arrays. Of course this will slow the program down, but at least it'll finish. Unless you need them all at once?

Gyppo
Well, yes, but the whole point of profiling is that I want to figure out *which* arrays I should write to file. If I try to write everything and pull it only when I need it, the I/O requirements would be enormous, and it would defeat the point.
thebackhand
+2  A: 

Looks like this question has already been answered here --> http://stackoverflow.com/questions/110259/python-memory-profiler

The answers given also includes a graphical browser.

+2  A: 

Dealing with large arays in numpy? Consider Numexpr http://www.scipy.org/SciPyPackages/NumExpr

it can reduce your calculation time by a factor of ten.

Mermoz
+1: NumExpr is indeed a good idea: it optimizes how memory is accessed during array operations, by transparently using the processor cache and minimizing the number of temporary arrays.
EOL