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
[email protected]
http://projects.scipy.org/mailman/listinfo/numpy-discussion