import httplib import timeit def MakeRequest(): print "Before" conn = httplib.HTTPConnection("localhost:8080") conn.request("GET", "/", '', {}) response = conn.getresponse() data = response.read() conn.close() print "After" print "" if __name__ == '__main__': NUMBER = 5 # Time the execution of the generation. t = timeit.Timer( 'MakeRequest()', 'from ' + __name__ + ' import MakeRequest\ngc.enable()' ) duration = t.timeit(NUMBER) print 'Average time : ' + str(duration / NUMBER)