Generic question regarding Python-code. How can I most effectively locate the worst parts of my Python-code with respect to memory usage?
See e.g. this small example
def my_func():
a = [1] * (12 ** 4)
return a
def my_func2():
b = [2] * (10 ** 7)
return b
if __name__ == '__main__':
a1 = my_func()
a2 = my_func2()
How can I in an automated way tell that a2 is much larger that a1 in size?
And how can I - still automated - root this back towards my_func1()
and my_func2()
?
For C/C++ code I would use valgrind --tool=massif
, which can directly locate the heavy-weights regarding memory usage - but for Python I need your help.
Meliae appears to give some of the answer, but not nearly as good as massif does for C/C++.