|
.... forgot the attachment, sorry. Matt Doran wrote: Hi there, |
from sqlobject import *
import os
import datetime
db_filename = os.path.abspath('sqlite.db')
if os.path.exists(db_filename):
os.unlink(db_filename)
if db_filename[1] == ':':
# Fix path for windows
db_filename = db_filename[0] + "|" + db_filename[2:]
connection_string = 'sqlite:/' + db_filename
connection = connectionForURI(connection_string)
connection.autoCommit = False
sqlhub.processConnection = connection
class Test(SQLObject):
number = IntCol()
desc = StringCol()
Test.createTable()
NUM_INSERTS = 100
if True:
trans = connection.transaction()
#connection.debug = True
start = datetime.datetime.now()
for i in range(1, NUM_INSERTS):
#print i
t = Test(number=i, desc="desc" + str(i))
trans.commit()
stop = datetime.datetime.now()
print "sqlobject: Inserting %d rows took: %s Per Insert: %s" %
(NUM_INSERTS, str(stop - start), str((stop - start) / NUM_INSERTS))
connection.close()
####################
if True:
from pysqlite2 import dbapi2 as sqlite
con = sqlite.connect("sqlite.db")
cur = con.cursor()
start = datetime.datetime.now()
for i in range(NUM_INSERTS + 1, NUM_INSERTS * 2):
#print i
cur.execute("insert into test (number, desc) values (?, ?);", (i,
"desc" + str(i)))
con.commit()
stop = datetime.datetime.now()
print "pysqlite: Inserting %d rows took: %s Per Insert: %s" %
(NUM_INSERTS, str(stop - start), str((stop - start) / NUM_INSERTS))
con.close()
