test_profile.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:ripozo-mongokit 作者: igoryk 项目源码 文件源码
def profileit(func):
    """
    Decorator straight up stolen from stackoverflow
    """
    def wrapper(*args, **kwargs):
        datafn = func.__name__ + ".profile" # Name the data file sensibly
        prof = cProfile.Profile()
        prof.enable()
        retval = prof.runcall(func, *args, **kwargs)
        prof.disable()
        stats = pstats.Stats(prof)
        stats.sort_stats('tottime').print_stats(20)
        print()
        print()
        stats.sort_stats('cumtime').print_stats(20)
        return retval

    return wrapper
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号