I have recently started using the python memory profiler from here. As a test run, I tried to profile the toy code from here following the instructions therein. I have some naive questions on the outputs I saw.
import time
@profile
def test1():
n = 10000
a = [1] * n
time.sleep(1)
return a
@profile
def test2():
n = 100000
b = [1] * n
time.sleep(1)
return b
if __name__ == "__main__":
test1()
test2()
This is the output using mprof run and then plot command line options:
After removing the @profile lines, I ran the profiler again and obtained the following result:
Except for the brackets for the functions, I was expecting almost identical plots (since the code is simple), but I am seeing some significant differences such as the ending time of the plot, variations within brackets etc.
Can someone please shed light into these differences?
Edit:
For small intervals, the plot with function profiling looks like:
The differences you are seeing are probably due to the fact that the information stored by @profile is counted within the total memory used by the program. There is also a slight overhead of storing this information, hence the different running times.
Also, you might get slightly different plots in different runs just due to variations in how Python manages memory.