import httplib
import urllib2
import time

H = httplib.HTTPConnection('2ch.hk')
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():
    H.request('GET', '/b/', headers={'Connection': 'keep-alive'})
    H.getresponse().read()


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


print('HTTPlib')
httplib_test()
print('urllib')
urllib_test()
