Skip to content

Instantly share code, notes, and snippets.

@iht
Created November 21, 2020 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iht/0e57987b8da77299d94795f14b629aba to your computer and use it in GitHub Desktop.
Save iht/0e57987b8da77299d94795f14b629aba to your computer and use it in GitHub Desktop.
Filter the stats for our modules only and sort by average time per function
def is_my_key(key, modules):
""" Returns True if the key belongs to one of the modules.
Args:
key: key of the stats dictionary.
modules: list of strings with the modules to be matched.
"""
fn = key[0]
for m in modules:
module_name = '%s' % m
if module_name in fn:
return True
return False
stats_dict = p.sort_stats('cumulative').stats
mymodules = ['dofns', 'pipeline']
mykeys = [k for k in stats_dict.keys() if is_my_key(k, mymodules)]
mystats = {k: stats_dict[k] for k in mykeys}
percall = {}
for k,v in mystats.items():
_, ncalls, _, cumtime, _ = v
avg_time = cumtime/ncalls
percall[k] = avg_time
sorted(percall.items(), key=lambda x: x[1], reverse=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment