<s> from multiprocessing . pool import ThreadPool <EOL> import requests <EOL> import optparse <EOL> import timeit <EOL> import time <EOL> parser = optparse . OptionParser ( ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store>" , dest = "<STR_LIT:url>" , help = "<STR_LIT>" , default = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store>" , dest = "<STR_LIT>" , help = "<STR_LIT>" , default = <NUM_LIT> ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store>" , dest = "<STR_LIT>" , help = "<STR_LIT>" , default = <NUM_LIT:8> ) <EOL> ( options , args ) = parser . parse_args ( ) <EOL> if options . url is None : <EOL> parser . error ( "<STR_LIT>" ) <EOL> pool = ThreadPool ( options . threads ) <EOL> def main ( ) : <EOL> pool . map ( worker , range ( options . threads ) , <NUM_LIT:1> ) <EOL> def carry_request ( ) : <EOL> start = time . time ( ) <EOL> r = requests . get ( options . url ) <EOL> data = r . text <EOL> if r . status_code != <NUM_LIT:200> : <EOL> print "<STR_LIT>" <EOL> end = time . time ( ) <EOL> report_elapsed ( end - start ) <EOL> elapsed_total = <NUM_LIT:0> <EOL> elapsed_num = <NUM_LIT:0> <EOL> def worker ( n ) : <EOL> while elapsed_num <= options . number : <EOL> carry_request ( ) <EOL> def report_elapsed ( elapsed ) : <EOL> global elapsed_num , elapsed_total <EOL> elapsed_num += <NUM_LIT:1> <EOL> elapsed_total += elapsed <EOL> print "<STR_LIT>" % ( elapsed_total / elapsed_num ) <EOL> print "<STR_LIT>" % ( elapsed ) <EOL> main ( ) </s>
