By default, Python contains a profiler called cProfile. It not only gives the total running time, but also times each function separately, and tells you how many times each function was called, making it easy to determine where you should make optimizations.
You can call it from within your code:
Even more usefully, you can invoke the cProfile when running a script:
With the output similar to this:
To learn more about cProfile, you can visit the official documentation.
Got an article suggestion?
Let us know
BY
NC
SA
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.