You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
profile result with unexpected big negative number #211
I want to profile the memory usage of objects with the codes below:
from memory_profiler import profile
NUM = 100000
class Person(object):
def __init__(self, name):
self.name = name
@profile
def run1():
ps = []
for i in range(NUM):
ps.append(Person(str(i)))
@profile
def run2():
r = []
for _ in range(NUM):
r.append({})
if __name__ == "__main__":
run1()
run2()
And I get the result:
$ python -m memory_profiler demo.py
Filename: demo.py
Line # Mem usage Increment Line Contents
================================================
12 10.8 MiB 10.8 MiB @profile
13 def run1():
14 10.8 MiB 0.0 MiB ps = []
15 53.1 MiB -744.4 MiB for i in range(NUM):
16 53.1 MiB -711.9 MiB ps.append(Person(str(i)))
Filename: demo.py
Line # Mem usage Increment Line Contents
================================================
18 14.8 MiB 14.8 MiB @profile
19 def run2():
20 14.8 MiB 0.0 MiB r = []
21 42.4 MiB -47.0 MiB for _ in range(NUM):
22 42.4 MiB -19.5 MiB r.append({})
The run1 line:15 and line:16 have a big negative number.
But if I change the global NUM to 10000, the result is total different:
$ python -m memory_profiler demo.py
Filename: demo.py
Line # Mem usage Increment Line Contents
================================================
12 10.7 MiB 10.7 MiB @profile
13 def run1():
14 10.7 MiB 0.0 MiB ps = []
15 15.1 MiB 0.3 MiB for i in range(NUM):
16 15.1 MiB 4.0 MiB ps.append(Person(str(i)))
Filename: demo.py
Line # Mem usage Increment Line Contents
================================================
18 11.6 MiB 11.6 MiB @profile
19 def run2():
20 11.6 MiB 0.0 MiB r = []
21 14.2 MiB 0.0 MiB for _ in range(NUM):
22 14.2 MiB 2.6 MiB r.append({})
How to explain the different between the two cases?
Should I consider the loop or something else, thanks.
Thanks for the insightful bug report @bingoabs! This seems related to #195, could you please pip install https://github.com/fabianp/memory_profiler/archive/fix_195.zip and check if it fixes the issue?
Activity
astrojuanlu commentedon Sep 27, 2018
Thanks for the insightful bug report @bingoabs! This seems related to #195, could you please
and check if it fixes the issue?pip install https://github.com/fabianp/memory_profiler/archive/fix_195.zipastrojuanlu commentedon Sep 27, 2018
Sorry, I meant
pip install https://github.com/pythonprofilers/memory_profiler/archive/master.zip.bingoabs commentedon Dec 26, 2018
I test and find the result is normal. I am sorry to reply so late.
fabianp commentedon Jan 4, 2019
thanks for confirming @bingoabs !