Skip to content

[dev] Profiling

Infernio edited this page Feb 7, 2022 · 6 revisions

Profiler calls for Python, copy-paste ready (because I keep forgetting the syntax and trudging through git reflog is no fun). You can set these up with PyCharm as live templates too.

See also [dev] Parent call tracing for a useful recipe for figuring out where those calls are coming from.

Enable (put before code you want to profile)

import cProfile, pstats, io
pr = cProfile.Profile()
pr.enable()

Disable (put after code you want to profile)

pr.disable()
s = io.StringIO()
ps = pstats.Stats(pr, stream=s).sort_stats('cumtime')
ps.print_stats()
bolt.deprint(s.getvalue())
Clone this wiki locally