Python测试Sqlite代码
2018-07-20 来源:open-open
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)
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:插入排序
下一篇: getchar putchar函数用法
最新资讯
热门推荐