Python Forum

Full Version: Get average of multiple threads
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
Is there a way to get the average of all the requests. I am able to get the response time per execution as below(running as a loop). But is there a way to sum all of these and get the average?

Output:
Thread 0
Thread 1
request: 1 Status: 200OK ResponseTime: 0.003963258999999941
request: 0 Status: 200OK ResponseTime: 0.005142219999999975
Thread 0
Thread 1
request: 0 Status: 200OK ResponseTime: 0.004329180999999904
request: 1 Status: 200OK ResponseTime: 0.004248067999999994

I basically want to get the get the average of all the 4 entries above. NOTE: i am using
start = time.process_time() & request_time = time.process_time() - start to get the response time.
Thanks!!
#Just before starting threads
thread_times = []
start_time = process_time()

#In each thread
thread_times.append(process_time() - start_time)

#When all are done
print('Average time =', mean(thread_times))