#NEWLINE# def run_size_benchmarks( url = '' , cycles = 10 , delay = None , output_file = None , length_api_format = '/length/$length' , **kwargs ) : #NEWLINE# #INDENT# timer_type = kwargs . get ( 'timer' ) #NEWLINE# ' Run variable-size benchmarks, where URL is the base url ' #NEWLINE# sizes = [ 4 , 512 , 1024 , 2048 , 4096 , 8192 , 16384 , 32768 , 65536 , 131072 ] #NEWLINE# REQUESTS_NOREUSE = ( 'requests' , False , 'Default' , 'import requests' , "r = requests.get('$url', verify=False)" ) #NEWLINE# REQUESTS_REUSE = ( 'requests' , True , 'Default' , "import requests;             session = requests.Session();             r = requests.Request('GET', '$url').prepare()" , 'v = session.send(r, verify=False)' ) #NEWLINE# PYCURL_REUSE = ( 'pycurl' , True , 'Reuse handle, save response to new cStringIO buffer' , "from pycurl import Curl; from cStringIO import StringIO;             mycurl=Curl();             mycurl.setopt(mycurl.SSL_VERIFYPEER, 0);             mycurl.setopt(mycurl.SSL_VERIFYHOST, 0);             mycurl.setopt(mycurl.URL, '$url')" , 'body = StringIO();             mycurl.setopt(mycurl.WRITEFUNCTION, body.write);             mycurl.perform();             val = body.getvalue();             body.close()' ) #NEWLINE# PYCURL_NOREUSE = ( 'pycurl' , False , 'Reuse handle, save response to new cStringIO buffer' , "from pycurl import Curl; from cStringIO import StringIO;             mycurl=Curl();             mycurl.setopt(mycurl.URL, '$url');             mycurl.setopt(mycurl.SSL_VERIFYPEER, 0);             mycurl.setopt(mycurl.SSL_VERIFYHOST, 0);             body = StringIO();             mycurl.setopt(mycurl.FORBID_REUSE, 1)" , 'body = StringIO();             mycurl.setopt(mycurl.WRITEFUNCTION, body.write);             mycurl.perform();             val = body.getvalue();             body.close()' ) #NEWLINE# TEST_TYPES = [ REQUESTS_NOREUSE , PYCURL_NOREUSE , REQUESTS_REUSE , PYCURL_REUSE ] #NEWLINE# all_results = list ( ) #NEWLINE# for size in sizes : #NEWLINE# #INDENT# temp_url = ( url + string . Template ( length_api_format ) . substitute ( length = size ) ) #NEWLINE# for test in TEST_TYPES : #NEWLINE# #INDENT# result = run_test ( test [ 0 ] , temp_url , cycles , test [ 1 ] , test [ 2 ] , test [ 3 ] , test [ 4 ] , delay = delay , timer = timer_type ) #NEWLINE# del result [ 3 ] #NEWLINE# result . insert ( 0 , size ) #NEWLINE# all_results . append ( result ) #NEWLINE# #UNINDENT# #UNINDENT# final_output = [ [ x , 0 , 0 , 0 , 0 ] for x in sizes ] #NEWLINE# for i in xrange ( 0 , len ( sizes ) ) : #NEWLINE# #INDENT# final_output [ i ] [ 1 ] = all_results [ ( i * 4 ) ] [ 4 ] #NEWLINE# final_output [ i ] [ 2 ] = all_results [ ( ( i * 4 ) + 1 ) ] [ 4 ] #NEWLINE# final_output [ i ] [ 3 ] = all_results [ ( ( i * 4 ) + 2 ) ] [ 4 ] #NEWLINE# final_output [ i ] [ 4 ] = all_results [ ( ( i * 4 ) + 3 ) ] [ 4 ] #NEWLINE# #UNINDENT# headers = ( 'Response_size' , 'Requests Time (no cnxn reuse)' , 'pyCurl Time (no cnxn reuse)' , 'Requests Time (cnxn reuse)' , 'pyCurl Time (cnxn reuse)' ) #NEWLINE# if output_file : #NEWLINE# #INDENT# with open ( output_file , 'wb' ) as csvfile : #NEWLINE# #INDENT# outwriter = csv . writer ( csvfile , dialect = csv . excel ) #NEWLINE# outwriter . writerow ( headers ) #NEWLINE# for result in final_output : #NEWLINE# #INDENT# outwriter . writerow ( result )