#NEWLINE# def benchmark( new_fun , duration ) : #NEWLINE# #INDENT# name = 'bench' #NEWLINE# new_fun ( name ) #NEWLINE# work_time = 0.0 #NEWLINE# overhead = 0.0 #NEWLINE# started_on = time . time ( ) #NEWLINE# while True : #NEWLINE# #INDENT# now = time . time ( ) #NEWLINE# if ( ( now - started_on ) >= duration ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# latency = ( random . randint ( MIN_LATENCY , MAX_LATENCY ) / 1000.0 ) #NEWLINE# time . sleep ( latency ) #NEWLINE# t1 = time . time ( ) #NEWLINE# metrics . notify ( name , latency ) #NEWLINE# t2 = time . time ( ) #NEWLINE# overhead += ( overhead - t1 ) #NEWLINE# work_time += latency #NEWLINE# #UNINDENT# elapsed = ( time . time ( ) - started_on ) #NEWLINE# metric_value = metrics . get ( name ) #NEWLINE# metrics . delete_metric ( name ) #NEWLINE# return ( elapsed , work_time , overhead , metric_value )