I want to know how to profile my code.
I have gone through the docs, but as there were no examples given I could not get anything from it.
I have a large code and it is taking so much time, hence I want to profile and increase its speed.
I havent written my code in method, there are few in between but not completely.
I don’t have any main in my code. I want to know how to use profiling.
I’m looking for some example or sample code of about how to profile.
I tried psyco, i.e just addded two lines at the top of my code:
import psyco
psyco.full()
Is this right? It did not show any improvement.
Any other way of speeding up, please suggest.
The standard answer to this question is to use cProfile.
You’ll find though that without having your code separated out into methods that cProfile won’t give you particularly rich information.
Instead, you might like to try what another poster here calls Monte Carlo Profiling. To quote from another answer:
It’s not orthodox, but I’ve used it very successfully in a project where profiling using cProfile was not giving me useful output.
The best thing about it is that this is dead easy to do in Python. Simply run your Python script in the interpreter, press [Control-C], note the traceback and repeat a number of times.