🐍 Python - Call Profiling
Updated at 2019-01-26 19:16
How to profile function calls and their durations in Python:
import cProfile
import io
import pstats
pr = cProfile.Profile()
pr.enable()
# do the thing you want to profile
pr.disable()
s = io.StringIO()
ps = pstats.Stats(pr, stream=s).sort_stats('cumulative')
ps.print_stats()
print(s.getvalue())