Calculating Elapsed Time

Fredrik Lundh fredrik at
Wed Dec 7 17:19:31 CET 2005

Peter Hansen wrote:

> Going by memory, Linux will generally be 1ms resolution (I might be
> off by 10 there...), while Windows XP has about 64 ticks per second,
> so .015625 resolution...

here's a silly little script that measures the difference between
two distinct return values, and reports the maximum frequency
it has seen this far:

    import time

    def test(func):
        mm = 0
        t0 = func()
        while 1:
            t1 = func()
            if t0 != t1:
                m = max(1 / (t1 - t0), mm)
                if m != mm:
                    print m
                    mm = m
                t0 = t1

    # test(time.clock)

if I run this on the Windows 2K box I'm sitting at right now, it settles
at 100 for time.time, and 1789772 for time.clock.  on linux, I get 100
for time.clock instead, and 262144 for time.time.


More information about the Python-list mailing list