import httplib
import urllib2
import time
import requests

HTTPLIB_CON = httplib.HTTPConnection('2ch.hk')
REQUESTS_SESSION = requests.Session()
TIMES = 1000


def timeit(times):
    def decorator(func):

        def _f(*args, **kwargs):
            start = time.time()
            for _ in range(times):
                func(*args, **kwargs)
            print('finished in %s' % (time.time() - start))
        return _f

    return decorator


@timeit(TIMES)
def httplib_test():
    HTTPLIB_CON.request('GET', '/b/', headers={'Connection': 'keep-alive'})
    HTTPLIB_CON.getresponse().read()


@timeit(TIMES)
def urllib_test():
    urllib2.urlopen('http://2...content-available-to-author-only...h.hk/b/').read()


@timeit(TIMES)
def requests_test():
    r = REQUESTS_SESSION.get('http://2...content-available-to-author-only...h.hk/b/')
    r.text


print('requests')
requests_test()

print('HTTPlib')
httplib_test()

print('urllib')
urllib_test()
