response time

Alex Martelli aleax at aleax.it
Mon Nov 10 15:12:45 EST 2003


José wrote:

> I'm programming a simple script to calculate response time from one
> server to another server.
> I put the time in secons in a variable. I take the web, and I take the
> time again, the difference is the time one servers takes to take the page.
> 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
therefore in seconds _and fractions_; whether the precision is (e.g.)
1/100 of a second, or 1/1000 of a second, or whatever, depends on
what platform you're running.  In any case, just multiply that difference
by 1000 and you'll have it in milliseconds (possibly rounded e.g. to the
closest 10 milliseconds if you underlying platform doesn't provide
better precision than that, of course).


Alex





More information about the Python-list mailing list