Here are some simple ways to profile Python scripts.I heavily use this to check my Project Euler solutions
The main common option would be to use the profile
) module.There are two different ways of using it :
- As a module, by directly running
```python -m cProfile script.py```
- In your code, by importing the utilities
cProfile.run('function()') # in your __main__
Bonus : You can use several options for sorting results using the -s switch (cumulative/name/time/file sorting are available).
If you want to avoid using a command line, or you don't have the profile module installed; here os another possibility. There is also the timeit
t1 = timeit.Timer("function()", "from __main__ import function")
I use this option on Eclipse because I didn't want to install the profile module on Windows.
This is however less clear, and way less detailed while still useful :).
Choose you profiler option and get on Project Euler
You've successfully subscribed to Figuring out Developer Relations, one day at a time!.
Great! You've successfully signed up.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.