Created
November 21, 2020 23:32
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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