File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ import requests
2
+ import time
3
+ import threading
4
+
5
+ api_list = [
6
+ 'https://api.example.com/endpoint1' ,
7
+ 'https://api.example.com/endpoint2' ,
8
+ 'https://api.example.com/endpoint3' ,
9
+ ]
10
+
11
+ num_tests = 10
12
+
13
+ def test_api (api ):
14
+ response_times = []
15
+
16
+ for i in range (num_tests ):
17
+ start_time = time .time ()
18
+ response = requests .get (api )
19
+ end_time = time .time ()
20
+
21
+ response_time = (end_time - start_time ) * 1000
22
+ response_times .append (response_time )
23
+
24
+ avg_response_time = sum (response_times ) / len (response_times )
25
+
26
+ print (f'API: { api } ' )
27
+ print (f'Average response time: { avg_response_time :.2f} ms\n ' )
28
+
29
+ # Loop through the API list and test each API using a separate thread
30
+ threads = []
31
+ for api in api_list :
32
+ thread = threading .Thread (target = test_api , args = (api ,))
33
+ thread .start ()
34
+ threads .append (thread )
35
+
36
+ # Wait for all threads to complete
37
+ for thread in threads :
38
+ thread .join ()
You can’t perform that action at this time.
0 commit comments