【问题标题】:Correct Way To Use cProfile正确使用 cProfile 的方法
【发布时间】:2016-10-20 01:46:42
【问题描述】:

我想对我编写的一些函数进行概要分析。我正在查看 cProfile 的文档,但我不明白以下两段代码之间的区别(如果有的话)是:

import cProfile

profile = cProfile.Profile()
result = profile.runcall(func, *args, **kwargs)
profile.dump_stats('profile.stats')

import cProfile

profile = cProfile.Profile()
profile.enable()
result = func(*args, **kwargs)
profile.disable()
profile.dump_stats('profile.stats')

这两个块是等价的,还是做些微妙的不同的事情?

【问题讨论】:

    标签: python cprofile


    【解决方案1】:

    它们几乎相同:https://github.com/python/cpython/blob/581eb3e0dc0bc0d306363c8d404ffd9988b0cc87/Lib/cProfile.py#L106

    runcall 将在出现异常时停止分析,否则功能相同。

    【讨论】:

    • 那么简单而全面。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-17
    • 2012-02-23
    • 2013-01-09
    相关资源
    最近更新 更多