I am wondering if it is possible for Python in VSCode (or anywhere else) that I can generate a running time report to evaluate the performance of codes, which means I can know the running time of each function or even each line with some clicks instead of measuring them phase by phase. And that is like the ‘run and time’ button in MATLAB. Thanks!
Question posted in Visual Studio Code
View the official documentation.
View the official documentation.
2
Answers
If you are using Linux, you can write this for python code to run:
This will get you the time it takes for your program to run. You can use it with
-v
for more verbose, something like this:Also, you can use the below code to print the execution time of your program manually:
I think what you need is not only the time at the end of the code run, but also the total time required to run part of the code.
You can try to use jupyter notebook to split the code into cells, so that you can count the time spent in running some code.
.ipynb
file and write codes in the cell.