I am trying to measure the memory usage of the following function for factoring integers.
def trialDiv(n):
a = []
f = 2
while n != 1:
if n % f == 0:
a.append(f)
n = n / f
else:
f = f + 1
return a
I am working in jupyter notebook and using memory_profiler. However, whenever I try and measure the memory usage of trialDiv by running
%mprun -f trialDiv trialDiv(n)
I get the following output.
Line # Mem usage Increment Line Contents
9 89.6 MiB 89.6 MiB def trialDiv(n):
10 89.6 MiB 0.0 MiB a = []
11 89.6 MiB 0.0 MiB f = 2
12 89.6 MiB 0.0 MiB while n != 1:
13 89.6 MiB 0.0 MiB if n % f == 0:
14 89.6 MiB 0.0 MiB a.append(f)
15 89.6 MiB 0.0 MiB n = n / f
16 else:
17 89.6 MiB 0.0 MiB f = f + 1
18 89.6 MiB 0.0 MiB return a
This is what is outputted regardless of the size of the integer passed into trialDiv. I feel like the function may not even be running at all or I am incorrectly using %mprun. Any advice would be appreciated.