[Tutor] time taken to execute certain task
Modulok
modulok at gmail.com
Thu Mar 17 07:15:35 CET 2011
On 3/16/11, tee chwee liong <tcl76 at hotmail.com> wrote:
>
> hi,
>
> 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):
> start=time.time()
> #print start
> for n in range(num):
> #print n
> print time.time()-start
>
> testtime(101)
>
> start = time.clock()
> for x in range(101):
> y = x # do something
> end = time.clock()
> print "Time clock elapsed = ", end - start, "seconds"
>
> thanks
> tcl
>
Also look into the builtin module 'timeit' if you're trying to benchmark things.
-Modulok-
More information about the Tutor
mailing list