最近研究了下jmeter上tps和平均响应时间的统计数据,自己顺便用python代码简写了一个小demo,记录一下
import requests,time def get_res(): tps = [] count = 0 start = time.time() response_time = [] time1 = 0 while True: res = requests.get('https://www.baidu.com/') end = time.time() if end - start < 1: count+=1 time1 += res.elapsed.total_seconds() else: response_time.append(round(time1/count,4)) time1 = res.elapsed.total_seconds() tps.append(count) count=1 start = end if len(tps) > 10: return tps,response_time start_time = time.time() print(get_res()) print(time.time()-start_time)