[Tutor] Python execution timer/proficiency testing

Steven D'Aprano steve at pearwood.info
Tue Aug 27 08:18:11 CEST 2013


On Mon, Aug 26, 2013 at 08:20:30PM +0200, Dino Bektešević wrote:
> Hello,
> 
> I'm interested in learning more about testing a program proficiency and how
> to measure execution times in seconds. I have a very repetitive functions

For the record, "proficiency" means skill, and is used when talking 
about people. You and I can have proficiency with Python. A Python 
program doesn't have proficiency. It has efficiency, how fast it 
operates, how much memory it requires.

For timing very small, *fast* code snippets, the best tool is the timeit 
module:

http://docs.python.org/2/library/timeit.html

For timing long-running pieces of code, I use this simple recipe:

http://code.activestate.com/recipes/577896-benchmark-code-with-the-with-statement/

To find out where a function is spending most of its time, 
you want a profiler, such as profile and hotshot:

http://docs.python.org/2/library/debug.html


> Warning (from warnings module):
>   File "/usr/lib/python2.7/dist-packages/scipy/optimize/minpack.py", line
> 152
>     warnings.warn(msg, RuntimeWarning)
> RuntimeWarning: The iteration is not making good progress, as measured by
> the improvement from the last ten iterations.
> 
> It doesn't seem to produce any error in my data, but how dangerous is this?

That's just telling you that your code is slow.

I say "your code", but it might be scipy, numpy, or code you wrote 
yourself. Or it might simply be that the task you are trying to do is 
hard, and no matter what you do it will always be slow. I'm afraid that 
it will probably take a numpy/scipy expert to tell you which is the 
case.


-- 
Steven


More information about the Tutor mailing list