import httplib import timeit def MakeRequest(): content = \ '' + '\n' + \ '' + '\n' + \ ' hello world' + '\n' + \ '' + '\n' + \ '' headers = { "Content-Type" : "application/xml; charset=iso-8859-1" , "Content-Length" : len(content) } conn = httplib.HTTPConnection("localhost:8080") conn.request("POST", "/", content, headers) response = conn.getresponse() data = response.read() conn.close() if __name__ == '__main__': NUMBER = 10 # 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)