<s> import time <EOL> import numpy as np <EOL> from IPython import parallel <EOL> nlist = list ( map ( int , np . logspace ( <NUM_LIT:2> , <NUM_LIT:9> , <NUM_LIT:16> , base = <NUM_LIT:2> ) ) ) <EOL> nlist2 = list ( map ( int , np . logspace ( <NUM_LIT:2> , <NUM_LIT:8> , <NUM_LIT:15> , base = <NUM_LIT:2> ) ) ) <EOL> tlist = list ( map ( int , np . logspace ( <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:16> , base = <NUM_LIT:2> ) ) ) <EOL> nt = <NUM_LIT:16> <EOL> def wait ( t = <NUM_LIT:0> ) : <EOL> import time <EOL> time . sleep ( t ) <EOL> def echo ( s = '<STR_LIT>' ) : <EOL> return s <EOL> def time_throughput ( nmessages , t = <NUM_LIT:0> , f = wait ) : <EOL> client = parallel . Client ( ) <EOL> view = client . load_balanced_view ( ) <EOL> if f is echo : <EOL> t = np . random . random ( t / <NUM_LIT:8> ) <EOL> view . apply_sync ( echo , '<STR_LIT>' ) <EOL> client . spin ( ) <EOL> tic = time . time ( ) <EOL> for i in range ( nmessages ) : <EOL> view . apply ( f , t ) <EOL> lap = time . time ( ) <EOL> client . wait ( ) <EOL> toc = time . time ( ) <EOL> return lap - tic , toc - tic <EOL> def do_runs ( nlist , t = <NUM_LIT:0> , f = wait , trials = <NUM_LIT:2> , runner = time_throughput ) : <EOL> A = np . zeros ( ( len ( nlist ) , <NUM_LIT:2> ) ) <EOL> for i , n in enumerate ( nlist ) : <EOL> t1 = t2 = <NUM_LIT:0> <EOL> for _ in range ( trials ) : <EOL> time . sleep ( <NUM_LIT> ) <EOL> ts = runner ( n , t , f ) <EOL> t1 += ts [ <NUM_LIT:0> ] <EOL> t2 += ts [ <NUM_LIT:1> ] <EOL> t1 /= trials <EOL> t2 /= trials <EOL> A [ i ] = ( t1 , t2 ) <EOL> A [ i ] = n / A [ i ] <EOL> print ( n , A [ i ] ) <EOL> return A <EOL> def do_echo ( n , tlist = [ <NUM_LIT:0> ] , f = echo , trials = <NUM_LIT:2> , runner = time_throughput ) : <EOL> A = np . zeros ( ( len ( tlist ) , <NUM_LIT:2> ) ) <EOL> for i , t in enumerate ( tlist ) : <EOL> t1 = t2 = <NUM_LIT:0> <EOL> for _ in range ( trials ) : <EOL> time . sleep ( <NUM_LIT> ) <EOL> ts = runner ( n , t , f ) <EOL> t1 += ts [ <NUM_LIT:0> ] <EOL> t2 += ts [ <NUM_LIT:1> ] <EOL> t1 /= trials <EOL> t2 /= trials <EOL> A [ i ] = ( t1 , t2 ) <EOL> A [ i ] = n / A [ i ] <EOL> print ( t , A [ i ] ) <EOL> return A </s>
