How can I get so-to-say page's response time: time between request is sent and the first header's byte comes?

PS: Here I don't want to deal with sockets - it would work, but it is too raw.

PPS: with curl in bash you can do it like this:

(time curl URL --head) 2>&1 | grep real | cut -c 6-
有帮助吗?

解决方案

This should get you going:

from timeit import Timer
from urllib2 import urlopen

def fetch():
    page = urlopen('http://www.google.com')
    return page.info()

timer = Timer(fetch)
print timer.timeit(1)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top