can any one tell how to calculate a execution time of a MSSQL stored procedure query using python. I have a query like this
import pyodbc
import timer
DSN ='DRIVER=FreeTDS;SERVER=255.8.12.34;PORT=1433;DATABASE=CustomerFile;UID=Cust;
PWD=Cust;TDS_Version=8.0;'
cnxn =pyodbc.connect(DSN)
cursor = cnxn.cursor()
cursor.execute("select * from db.customer")
d = cursor.fetchall()
print d
i want to know the execution time of the query. I dont know how to do that. Pls help
Expected output:
[(1, aa,vir,123/12, aaa@gmailcom,88898976),(2,bb,yuv,23/4, bbb@gmail.com,2124314)]
Time Taken To execute: 10s
from time import time
# your code here
tic = time()
cursor.execute("select * from db.customer")
toc = time()
print toc - tic
python
import datetime
init_time = datetime.datetime.now()
cursor.execute("select * from db.customer" )
end_time = datetime.datetime.now()
exec_time = end_time - init_time
print ( 'exec_time = {} seconds '.format( exec_time.seconds) )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.