fork download
  1. import httplib
  2. import urllib2
  3. import time
  4.  
  5. H = httplib.HTTPConnection('2ch.hk')
  6. TIMES = 1000
  7.  
  8.  
  9. def timeit(times):
  10. def decorator(func):
  11.  
  12. def _f(*args, **kwargs):
  13. start = time.time()
  14. for _ in range(times):
  15. func(*args, **kwargs)
  16. print('finished in %s' % (time.time() - start))
  17. return _f
  18.  
  19. return decorator
  20.  
  21.  
  22. @timeit(TIMES)
  23. def httplib_test():
  24. H.request('GET', '/b/', headers={'Connection': 'keep-alive'})
  25. H.getresponse().read()
  26.  
  27.  
  28. @timeit(TIMES)
  29. def urllib_test():
  30. urllib2.urlopen('http://2...content-available-to-author-only...h.hk/b/').read()
  31.  
  32.  
  33. print('HTTPlib')
  34. httplib_test()
  35. print('urllib')
  36. urllib_test()
  37.  
Runtime error #stdin #stdout #stderr 0.05s 13048KB
stdin
Standard input is empty
stdout
HTTPlib
stderr
Traceback (most recent call last):
  File "prog.py", line 34, in <module>
  File "prog.py", line 15, in _f
  File "prog.py", line 24, in httplib_test
  File "/usr/lib/python2.7/httplib.py", line 1052, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python2.7/httplib.py", line 1092, in _send_request
    self.endheaders(body)
  File "/usr/lib/python2.7/httplib.py", line 1048, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python2.7/httplib.py", line 892, in _send_output
    self.send(msg)
  File "/usr/lib/python2.7/httplib.py", line 854, in send
    self.connect()
  File "/usr/lib/python2.7/httplib.py", line 831, in connect
    self.timeout, self.source_address)
  File "/usr/lib/python2.7/socket.py", line 557, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno -2] Name or service not known