time (was Re: lists, performance..)

Alex Martelli aleax at aleax.it
Thu Oct 31 10:56:27 EST 2002


<posted & mailed>

gabor wrote:
        ...
> btw. is there a timing function in python?
> like 'time' in unix..

Module time in the Python standard library supplies a slightly
different functionality from Unix's time command.  In particular
time.clock() returns "what time it is right now" -- CPU time on
Unix-ish systems, very accurate elapsed-time on Windows.  So, to
time how long some operation takes, the standard idiom is:

import time

start = time.clock()
# the operations you want to time
stend = time.clock()

print "It took %.2f seconds" % (stend-start)


Alex




More information about the Python-list mailing list