urllib2 vs urllib3 vs requests
#!/usr/bin/env python2.7
import urllib2
import time
_ITERATIONS = 200
start_time = time.time()
for i in range(0, _ITERATIONS):
try:
response = urllib2.urlopen('http://localhost/tmp/derp.html')
except urllib2.HTTPError, e:
response = e
response.code
print 'time with urllib2: {0}'.format(time.time()-start_time)
import urllib3
start_time = time.time()
http = urllib3.PoolManager()
for i in range(0, _ITERATIONS):
response = http.request('GET', 'http://localhost/tmp/derp.html')
response.status
print 'time with urllib3: {0}'.format(time.time()-start_time)
import requests
start_time = time.time()
for i in range(0, _ITERATIONS):
response = requests.get('http://localhost/tmp/derp.html')
response.status_code
print 'time with requests: {0}'.format(time.time()-start_time)