-
I not an expert in profiling code and I've only used |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
For CPU profiling, line-by-line, I'd use line_profiler. The official library, which can be installed off PyPi with To profile a specific function, you can decorate the function with @profile
async def test():
number = 100
number /= 10
print(number)
return number The best part is that kernprof injects async def test():
number = 100
number /= 10
print(number)
return number
try:
test = profile(test)
except NameError:
pass . Recap:
|
Beta Was this translation helpful? Give feedback.
For CPU profiling, line-by-line, I'd use line_profiler. The official library, which can be installed off PyPi with
pip install line_profiler
, doesn't have support for generating profiler results every x seconds, it only generates profiler results when the bot stops. I usekernprof -lvz (file name here, like run.py)
. That's why I made a fork that has a command line flag to output to a file every x seconds. With this, you can do something likekernprof -lvzi 15 (file name here)
, and it'll output results to a file every 15 seconds. You can view profiling results withpython3 -m line_profiler ./run.py.lprof
(replace run.py with your file name, ending with a .lprof suffix).To profile a specif…