【效率】【性能】接口響應時間(使用fiddler工具、pythton request的elapsed方法)

一、使用fiddler工具查看接口響應時間

測試項:http接口響應時間

測試工具:fiddler

查看方法:

(1)選中單條URL,在右側的視圖中選擇statistics->overalll elapsed 的值爲接口響應時間

(2)設置把此字段列出來的方法:

在URL那一欄右鍵點擊,選擇customize columns,然後在彈框中選擇session timers、overall_elapsed

 

點擊add,添加成功後,效果如下:

通過監控此響應時間,比如發現一個接口響應時間超過5S,設置超過10S了,可暴露出具體哪個接口慢,通過優化接口的響應時間提升產品的性能,用戶體驗(對應的質量指標是效率)。

二、python+request查看接口響應時間

#encoding:utf-8

 

import requests

import logging

logging.basicConfig(level=logging.NOTSET)

url="http://cn.python-requests.org/zh_CN/latest/"

r = requests.get(url)

logging.info("begin")

s=r.elapsed.total_seconds()

logging.info("%s接口響應時間:%s",url,s)

logging.info("finish")

 

elapsed方法的官方文檔地址:http://cn.python-requests.org/zh_CN/latest/api.html#requests.Response

elapsed = None

The amount of time elapsed between sending the request and the arrival of the response (as a timedelta). This property specifically measures the time taken between sending the first byte of the request and finishing parsing the headers. It is therefore unaffected by consuming the response content or the value of the stream keyword argument.

翻譯:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章