Contents
测试SQLite
try-sqlite.py
1 from sqlite3 import *
2 import os, time, datetime, platform
3 path = "./testP.sqlite"
4 log = open("./testP.log", "a+")
5 con = connect(path)
6 def prepare():
7 global con
8 con.close()
9 try:
10 os.remove(path)
11 print path, 'deleted'
12 except (WindowsError):
13 pass
14 con = connect(path)
15
16 def testCreate(n):
17 c = con.cursor()
18 for i in xrange(n):
19 c.execute("create table test%d (id int)"%(i))
20 con.commit()
21 c.close()
22
23 def testInsert(n):
24 c = con.cursor()
25 c.execute("create table testinsert (id int)")
26 for i in xrange(n):
27 c.execute("insert into testinsert (id) values (%d)"%(i))
28 con.commit()
29 c.close()
30
31 def showTime(x, n):
32 begin=datetime.datetime.today()
33 x(n)
34 end =datetime.datetime.today()
35 print "run %s %d\t times"%(x.func_name,n), end-begin
36 log.write("%s %s run %s %d\t times %s\n"%(platform.node(),
37 platform.processor(),x.func_name,n, end-begin))
38 if __name__=='__main__':
39 prepare()
40 showTime(testCreate, 1000)
41 showTime(testInsert, 1000000)
反馈
创建 by -- ZoomQuiet [2009-07-21 07:27:34]