dmitrey wrote:
> Is the genutils module not included to standard CPython edition?
> First of all I'm interested in what is the best way for latter, for to 
> users not need installing anything else.
> Thx, D.
> 
> 
> Fernando Perez wrote:
>> On 5/12/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>>   
>>> It depends on what you're aiming at. If you want to compare different
>>> implementations of some expressions and need to know their average
>>> execution times you should use the timeit module. If you want to have
>>> the full execution time of a script, time.time (call at the begin and
>>> end, compute the difference, gives the elapsed time) and time.clock
>>> (under linux the cpu clock time used by the process) are the methods
>>> you want.
>>>     
>> Don't use time.clock, it has a nasty wraparound problem that will give
>> you negative times after a while, and effectively junk for very long
>> running processes.  This is much safer (from IPython.genutils):
>>
>>     def clock():
>>         """clock() -> floating point number
>>
>>         Return the *TOTAL USER+SYSTEM* CPU time in seconds since the start of
>>         the process.  This is done via a call to resource.getrusage, so it
>>         avoids the wraparound problems in time.clock()."""
>>
>>         u,s = resource.getrusage(resource.RUSAGE_SELF)[:2]
>>         return u+s
>>
>>
>> The versions for only user or only system time are obvious, and
>> they're already in IPython.genutils as well:
>>
>> http://projects.scipy.org/ipython/ipython/browser/ipython/trunk/IPython/genutils.py#L165
>>
>> Cheers,
>>
>> f
>> _______________________________________________
>> Numpy-discussion mailing list
>> Numpy-discussion@scipy.org
>> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>>
>>
>>
>>   
Have you looked at timeit?

25.9 timeit -- Measure execution time of small code snippets

New in version 2.3.

This module provides a simple way to time small bits of Python code. 
It has both command line as well as callable interfaces. It avoids a 
number of common traps for measuring execution times. See also Tim 
Peters' introduction to the ``Algorithms'' chapter in the Python 
Cookbook, published by O'Reilly.

The module defines the following public class:


class Timer( [stmt='pass' [, setup='pass' [, timer=<timer function>]]])

Class for timing execution speed of small code snippets.

Colin W.

_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to