measure python’s memory usage
November 20th, 2007 by Lawrence David
profiling running time in python is straightforward. what’s tricky is measuring how much memory your program is consuming. i’ve modified some code i found online to do the trick nicely; just import this PyVM module and insert the following into your program:
import PyVM
…
PyVM.MemoryUpdate(“memory usage here”)
PyVM.MemoryUpdate(“memory usage there”)
PyVM.MemoryUpdate(“memory usage etc.”)
what will print out in front of each message is: 1) how much additional memory was consumed since the last time MemoryUpdate was called; 2) how much total memory is being used. note that for now, this module will only function correctly when python is being called on a unix or linux machine.