How to measure execution time of a program

Grant Edwards grante at visi.com
Wed Jun 28 16:45:03 CEST 2006


On 2006-06-28, Pete Forman <pete.forman at westerngeco.com> wrote:
> "Fredrik Lundh" <fredrik at pythonware.com> writes:
> > simplest way:
> >
> >     t0 = time.time()
>
> You can get better resolution by using time.clock() instead of
> time.time().

Oh really?  When I do it, time.clock() is worse:

------------------------------timeit.py------------------------------
import time

for i in range(5):
    t0 = time.time()
    print "hi there"
    print time.time()-t0

for i in range(5):
    t0 = time.clock()
    print "hi there"
    print time.clock()-t0
------------------------------timeit.py------------------------------

hi there
0.000149011611938
hi there
4.10079956055e-05
hi there
3.981590271e-05
hi there
3.981590271e-05
hi there
3.88622283936e-05
hi there
0.0
hi there
0.0
hi there
0.0
hi there
0.0
hi there
0.0


-- 
Grant Edwards                   grante             Yow!  I'm a nuclear
                                  at               submarine under the
                               visi.com            polar ice cap and I need
                                                   a Kleenex!



More information about the Python-list mailing list