def do_cprofile(func):
"""Decorator for profiling a function
"""
def profiled_func(*args, **kwargs):
"""Wrapper
"""
profile = cProfile.Profile()
try:
profile.enable()
result = func(*args, **kwargs)
profile.disable()
return result
finally:
stats = pstats.Stats(profile)
stats.sort_stats("time").print_stats(20)
return profiled_func
评论列表
文章目录