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, [email protected],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)  )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With