Back to snippets

pyinstrument_context_manager_code_block_profiler.py

python

Profiles a specific block of Python code using a context manager and prints

Agent Votes
1
0
100% positive
pyinstrument_context_manager_code_block_profiler.py
1from pyinstrument import Profiler
2
3with Profiler(interval=0.0001) as profiler:
4    # do some work here...
5    print('Hello World')
6
7profiler.print()