How to use cProfile Analysis tool in Python
This article mainly introduces how to use the cProfile analysis tool in Python. It is very detailed and has certain reference value. Friends who are interested must finish reading it.
Description
1. Python contains a parser called cProfile.
2. Not only the total elapsed time is given, but also each function is timed separately and tells you how many times each function has been called, so it is easy to determine where to optimize.
It can be called from the code or from the interpreter, as follows:
Import cProfilecProfile.run ('foo ()')
Even more useful, you can call cProfile when you run the script:
Python-m cProfile myscript.py
To make it easier, a small batch file called "profile.bat" was made:
Python-m cProfile 1
So all you have to do is run:
Profile euler048.py above is all the content of this article entitled "how to use cProfile Analysis tools in Python". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!