I have a Python script and I would like to measure the amount of memory that it uses. I have tried memory_profiler
but I could not find the right option for me.
I would like something that I can use as:
results = {}
for i in range(10):
l = [1]*i*1000
memory = compute_used_memory()
results[i] = memory
in order to know the amount of memory used during different phases of the program.
EDIT: I do not have much experience but I'll try to explain the problem better. I need to deploy my code on a machine where I will have access only to a limited amount of memory (such as 1 GB). As a consequence I need to know how much memory my code will use. As the code will run incrementally with increasing complexity I need to make sure that the amount of memory used converges to a maximum value. For this reason I need to measure how the amount of memory used changes at different stage of the execution that is in this case represented by a for loop .
Hmm, if you are using python3.4 and later you can use the tracemalloc module
import tracemalloc
tracemalloc.start()
profiled_code_here
print("Current: %d, Peak %d" % tracemalloc.get_traced_memory())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With