计算接口执行时间
2015-03-24 本文已影响0人
python自动化测试
#-*-coding:utf8-*-
import httplib,datetime
def getRequest(testUrl,requestHeader):
conn = httplib.HTTPConnection("***.****.com")
conn.request(method="GET",url=testUrl,body="",headers=requestHeader)
response = conn.getresponse()
response.read()
def requestTime():
requestHeader = {"Device-Id":"***","Ticket":"***","Local-Version":"1"}
beforeTime = datetime.datetime.now()
getRequest("http://***.***.com/***",requestHeader)
afterTime = datetime.datetime.now()
print (beforeTime,afterTime)
print (afterTime-beforeTime)
requestTime()
ps:可以看出,我这个接口执行花费了34秒,算比较慢的。