def c_profile(sort_by='tottime'):
def decorator(func):
@wraps(func)
def wrapped(*args, **kwargs):
profiler = cProfile.Profile()
profiler.enable()
result = func(*args, **kwargs)
profiler.disable()
stream = StringIO()
stats = pstats.Stats(profiler, stream=stream).sort_stats(sort_by)
stats.print_stats(25)
print(stream.getvalue())
return result
return wrapped
return decorator
# https://zapier.com/engineering/profiling-python-boss/
评论列表
文章目录