Python測試Sqlite代碼

黑燈舞 9年前發布 | 1K 次閱讀 Python API DocsBuilder

from sqlite3 import *
import os, time, datetime, platform
path = "./testP.sqlite"
log = open("./testP.log", "a+")
con = connect(path)
def prepare():
   global con
   con.close()
   try:
       os.remove(path)
       print path, 'deleted'
   except (WindowsError):
       pass
   con = connect(path)

def testCreate(n): c = con.cursor() for i in xrange(n): c.execute("create table test%d (id int)"%(i)) con.commit() c.close()

def testInsert(n): c = con.cursor() c.execute("create table testinsert (id int)") for i in xrange(n): c.execute("insert into testinsert (id) values (%d)"%(i)) con.commit() c.close()

def showTime(x, n): begin=datetime.datetime.today() x(n) end =datetime.datetime.today() print "run %s %d\t times"%(x.func_name,n), end-begin log.write("%s %s run %s %d\t times %s\n"%(platform.node(), platform.processor(),x.func_name,n, end-begin)) if name=='main': prepare() showTime(testCreate, 1000) showTime(testInsert, 1000000)</pre>

 本文由用戶 黑燈舞 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!