response time

Peter Hansen peter at engcorp.com
Mon Nov 10 17:56:07 EST 2003


"John J. Lee" wrote:
> 
> Alex Martelli <aleax at aleax.it> writes:
> 
> > José wrote:
> >
> > > I'm programming a simple script to calculate response time from one
> > > server to another server.
> [...]
> > > I can only calculate it in seconds, is there a way to do it in
> > > miliseconds?
> >
> > After "import time", time.time() returns the time (elapsed since an
> > arbitrary epoch) with the unit of measure being the second, but the
> > precision being as high as the platform on which you're running will
> > allow.  The difference between two results of calling time.time() is
> [...]
> 
> Also note that Windows' time(), in particular, has a precision of only
> around 50 milliseconds (according to Tim Peters, so I haven't bothered
> to test it myself ;-).  Pretty strange.

Strange, but based on a relatively mundane thing: the frequency (14.31818MHz)
of the NTSC color sub-carrier which was used when displaying computer output 
on a TV.  This clock was divided by 3 to produce the 4.77MHz clock for the
original IBM PC (because oscillators were/are relatively expensive, so you
wanted to re-use them whenever possible, even if just a submultiple) and
then by 4 again to produce the clock signal that went to the chip involved
in time-keeping, which then counted on every edge using a 16-bit counter
which wrapped around every 65536 counts, producing one interrupt every 
65536/(14.31818*1000000/12) or about 0.5492 ms, which is about 18.2 ticks
per second.  So other than it being closer to 55 ms than 50, you're right.

Google searches with "18.2 14.31818" will produce lots of background for 
all that.

-Peter




More information about the Python-list mailing list