import requests
import time
import concurrent.futures
import json
class APITest(object):
def __init__(self):
self.url = 'http://'
self.token = ''
self.headers = {'Content-Type': 'application/json',
'app_token': self.token}
self.total_time = 0
self.data = {
}
def common_get_events_list(self):
t = time.time()
ret = requests.post(url=self.url, headers=self.headers, data=json.dumps(self.data))
# print(ret)
end = (time.time() - t) % 60
return end
def time_total(self):
with concurrent.futures.ThreadPoolExecutor(max_workers=5000) as executor:
res = {executor.submit(self.common_get_events_list) for i in range(10)}
for future in concurrent.futures.as_completed(res):
try:
data = future.result()
except Exception as exc:
pass
else:
self.total_time += data
print('common_get_events_list:接口响应的总时间为%s秒' % str(self.total_time))
print('common_get_events_list:平均时间为%s秒' % str(self.total_time / 10))
print('-' * 50)
if __name__ == '__main__':
api = APITest()
api.common_get_events_list()
api.time_total()