我想介绍一下我写的一些函数。我正在查看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')这两个街区是等同的,还是做着微妙不同的事情?
发布于 2016-10-20 01:55:43
它们几乎一样:https://github.com/python/cpython/blob/581eb3e0dc0bc0d306363c8d404ffd9988b0cc87/Lib/cProfile.py#L106
如果出现异常,runcall将停止分析,但否则将是相同的功能。
https://stackoverflow.com/questions/40144161
复制相似问题