Python 页面响应基准测试(头部)
我怎么才能获取所谓的 页面响应时间:也就是从发送请求到收到第一个响应头的时间?
附注:在这里我不想处理套接字(sockets)——虽然这样可以做到,但太复杂了。
附注二:在bash中使用curl可以这样做:
(time curl URL --head) 2>&1 | grep real | cut -c 6-
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)