Search code examples
pythonrequestweburllib2httplib

python page response benchmarking (headers)


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-

Solution

  • 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)