<s> import sys <EOL> import time <EOL> import grequests <EOL> from collections import defaultdict <EOL> def make_request ( id , wav ) : <EOL> url = '<STR_LIT>' + str ( id ) <EOL> headers = { '<STR_LIT:Content-Type>' : '<STR_LIT>' } <EOL> return grequests . post ( url , data = wav , headers = headers ) <EOL> def run_requests ( n , batch_size ) : <EOL> wav = open ( '<STR_LIT>' , '<STR_LIT:rb>' ) . read ( ) <EOL> requests = [ make_request ( id , wav ) for id in range ( <NUM_LIT:0> , n ) ] <EOL> return grequests . map ( requests , size = batch_size ) <EOL> def print_statistics ( responses ) : <EOL> responses_by_status = defaultdict ( list ) <EOL> for response in responses : <EOL> responses_by_status [ str ( response . status_code ) ] . append ( response . elapsed . total_seconds ( ) ) <EOL> for status_code , responses in responses_by_status . iteritems ( ) : <EOL> count = len ( responses ) <EOL> elapsed_time = sum ( responses ) / count <EOL> print "<STR_LIT>" % ( count , status_code , elapsed_time ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> if len ( sys . argv ) != <NUM_LIT:3> : <EOL> print "<STR_LIT>" <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> requests = int ( sys . argv [ <NUM_LIT:1> ] ) <EOL> batch_size = int ( sys . argv [ <NUM_LIT:2> ] ) <EOL> responses = run_requests ( requests , batch_size ) <EOL> print_statistics ( responses ) </s>
