python页面响应基准测试(标题)

python页面响应基准测试(标题),python,request,web,urllib2,httplib,Python,Request,Web,Urllib2,Httplib,我怎么能这么说页面的响应时间:从发送请求到第一个报头的字节到达之间的时间 PS:在这里我不想处理套接字-它可以工作,但它太粗糙了 PPS:使用bash中的curl,您可以这样做: (time curl URL --head) 2>&1 | grep real | cut -c 6- 这应该会让你开始: from timeit import Timer from urllib2 import urlopen def fetch(): page = urlopen('htt

我怎么能这么说页面的响应时间:从发送请求到第一个报头的字节到达之间的时间

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

PPS:使用bash中的curl,您可以这样做:

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

这应该会让你开始:

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)

可以我应该使用HEAD-request而不是GET吗?如果您真的只需要header,而不是urllib2,那么可以从httplib使用
HTTPConnection
。如果你想看的话,我可以更新答案。httplib的级别稍微低一点。谢谢你,内森。可能是halpful:urllib2对HEAD也有好处:)