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

  1. what peak memory , increment mean?
  2. 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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -