2

如何获得所谓页面的响应时间:发送请求和第一个标头字节到来之间的时间?

PS:在这里我不想处理套接字 - 它可以工作,但它太原始了。

PPS:在 bash 中使用 curl 你可以这样做:

(time curl URL --head) 2>&1 | grep real | cut -c 6-
4

1 回答 1

3

这应该可以帮助您:

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)
于 2012-01-29T07:21:20.807 回答