Good, I need some way to calculate the amount of memory that has been necessary to execute a series of instructions in Python. Something similar to time.clock()
, but for memory, some help.
Good, I need some way to calculate the amount of memory that has been necessary to execute a series of instructions in Python. Something similar to time.clock()
, but for memory, some help.
If you want something very detailed you could use memory_profiler but if the program is complex it may take a lot of time in giving you answers. This is used, mainly, to search memory leaks .
If you are only interested in obtaining the peak of memory used, the same creator of memory_profiler has this entry in your blog where you get this solution to get the memory used by the process that runs the Python script on any system operative:
def memory_usage_psutil():
# return the memory usage in MB
import psutil
import os
process = psutil.Process(os.getpid())
mem = process.memory_info().rss / float(2 ** 20)
return mem