Python测试Sqlite代码

2014-12-30 0 117
Python测试Sqlite代码
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)

遇见资源网 python Python测试Sqlite代码 http://www.ox520.com/14980.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务