[Tutor] time taken to execute certain task

tee chwee liong tcl76 at hotmail.com
Thu Mar 17 03:40:54 CET 2011

i would like to know the time taken to execute a certain task in python. i used time.time and time.clock and i see the time taken is different? what is the right method to use? 
import time
def testtime(num):
    #print start
    for n in range(num):
        #print n
        print time.time()-start

start = time.clock()
for x in range(101):
  y = x  # do something
end = time.clock()
print "Time clock elapsed = ", end - start, "seconds"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110317/3196dbc3/attachment.html>

More information about the Tutor mailing list