time.time or time.clock

dwblas at gmail.com dwblas at gmail.com
Mon Jan 14 12:50:14 EST 2008


"""
<snipped>
time.clock() isn't high enough resolution for Ubuntu, and time.time()
isn't
high enough resolution on windows.

Take a look at datetime.  It is good to the micro-second on Linux and
milli-second on Windows.
"""

import datetime
begin_time=datetime.datetime.now()
for j in range(100000):
   x = j+1     # wait a small amount of time
print "Elapsed time =", datetime.datetime.now()-begin_time

## You can also access the individual time values
print begin_time.second
print begin_time.microsecond     ## etc.



More information about the Python-list mailing list