Batman Batman - 1 year ago 154
Python Question

Correct Way To Use cProfile

I want to profile some functions that I've written. I'm looking at the docs for cProfile, and I don't understand what (if any) the difference between the following two pieces of code is:

import cProfile

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


import cProfile

profile = cProfile.Profile()
result = func(*args, **kwargs)

Are these two blocks equivalent, or are these doing subtly different things?

Answer Source

They're almost the same:

runcall will stop the profiling in case of exceptions, but otherwise it's the same functionality.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download