Trying to understand python memory profiler -
i using memory profiler module memory usage of python code following this answer. however, not able interpret output %memit
magic (or output using @profile
decorator module or mprof run
matter).
for instance,
%memit range(10000)
gives me peak memory: 97.41 mib, increment: 0.24 mib
while,
%memit xrange(10000)
shows peak memory: 97.46 mib, increment: 0.00 mib
. understand difference between xrange
returning xrange type
opposed range()
returning list. used them here demonstrate 2 scenarios.
my question
- what
peak memory
,increment
mean? - what should report total memory usage of script (or function) output?
peak memory refers peak memory usage of system (including memory usage of other processes) during program runtime.
increment increment in memory usage relative memory usage before program run (i.e. increment
= peak memory
- starting memory
).
so you'd report increment
. peak memory helps figure how close using ram during program run.
if refer line-by-line example in usage section of readme:
line # mem usage increment line contents ============================================== 3 @profile 4 5.97 mb 0.00 mb def my_func(): 5 13.61 mb 7.64 mb = [1] * (10 ** 6) 6 166.20 mb 152.59 mb b = [2] * (2 * 10 ** 7) 7 13.61 mb -152.59 mb del b 8 13.61 mb 0.00 mb return
%memit
giving memory usage line 6, reports increment relative line 4 (actually line 1, presumably, there's no computation in lines 1-3).
Comments
Post a Comment