Skip to content

Instantly share code, notes, and snippets.

@jcsaaddupuy
Created August 28, 2015 08:20
Show Gist options
  • Save jcsaaddupuy/836e3557452a5710e658 to your computer and use it in GitHub Desktop.
Save jcsaaddupuy/836e3557452a5710e658 to your computer and use it in GitHub Desktop.
python poorman profiling
import gc
import operator
from itertools import islice
types ={}
#
objs = gc.get_objects()
for x in objs:
types[type(x)] = (types.get(type(x)) or 0) +1
# sort types by occurences DESC
sorted_types = sorted(types.items(), key=operator.itemgetter(1), reverse=True)
print len(sorted_types)
# get 10 most used types
most_used = list(islice(sorted_types, 10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment