Skip to content

Instantly share code, notes, and snippets.

@myarik
Created March 2, 2016 09:38
Show Gist options
  • Save myarik/e009c0c881b49d1199c5 to your computer and use it in GitHub Desktop.
Save myarik/e009c0c881b49d1199c5 to your computer and use it in GitHub Desktop.
# Simple way
from pympler import summary, muppy
def go():
list1 = []
f = 5
for i in range(10000000):
f += 1
list1.append(f)
go()
all_objects = muppy.get_objects()
sum1 = summary.summarize(all_objects)
summary.print_(sum1)
# Find diff
from pympler import summary, muppy
sum1 = summary.summarize(muppy.get_objects())
summary.print_(sum1)
list1 = []
f = 5
for i in range(1000000):
f += 1
list1.append(f)
sum2 = summary.summarize(muppy.get_objects())
diff = summary.get_diff(sum1, sum2)
summary.print_(diff)
# Lib objgraph
import objgraph
objgraph.show_most_common_types()
# Lib guppy
from guppy import hpy
hp = hpy()
before = hp.heap()
# critical section here
#
after = hp.heap()
leftover = after - before
import pdb; pdb.set_trace()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment