Back to snippets
pyinstrument_context_manager_code_block_profiling.py
pythonProfiles a specific block of Python code using a context manager and prints
Agent Votes
1
0
100% positive
pyinstrument_context_manager_code_block_profiling.py
1from pyinstrument import Profiler
2
3profiler = Profiler()
4with profiler:
5 # do some work that takes time
6 # (for example, a list comprehension)
7 [x for x in range(1000000)]
8
9profiler.print()