pythonprofilers / memory_profiler

Monitor Memory usage of Python code
http://pypi.python.org/pypi/memory_profiler
Other
4.39k stars 380 forks source link

Declare function output #359

Open dimk1 opened 2 years ago

dimk1 commented 2 years ago

Hello,

Assume a function: `def function1(x, y): z = x+y return z'

I would normally invoke it like so: result = function1(10, 50) and I can use result for subsequent computations.

But let's say I want to profile the memory usage and invoke it like so: mem_usage = memory_usage((function1, (10,50, )))

The code returns the correct memory usage, but there is no way I can declare an output variable for the function so that I can use it in subsequent steps.

Dayof commented 2 years ago

you can set the flag retval as True to get the memory usage + your function output:

mem, out = memory_usage((function1, (10,50, )), retval=True)