【问题标题】:python page response benchmarking (headers)python页面响应基准测试(标题)
【发布时间】:2012-01-29 06:23:55
【问题描述】:

我怎样才能得到所谓的页面响应时间:从请求发送到第一个标头字节到来的时间?

PS:这里我不想处理套接字——它会工作,但它太原始了。

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

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

【问题讨论】:

    标签: python request web urllib2 httplib


    【解决方案1】:

    这应该可以帮助您:

    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 请求而不是 GET 吗?
    • 如果你真的只想要头部,而不是 urllib2,你可以使用 httplib 中的HTTPConnection。如果您想看到,我可以更新答案。 httplib 的级别有点低。
    • 谢谢,内森。它可能是 halpful:urllib2 对 HEAD 也有好处 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-07
    • 1970-01-01
    • 1970-01-01
    • 2014-02-26
    • 1970-01-01
    • 2019-06-06
    • 1970-01-01
    相关资源
    最近更新 更多