]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
a mass insert/ select benchmarking test, from
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 14 Aug 2007 17:34:17 +0000 (17:34 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 14 Aug 2007 17:34:17 +0000 (17:34 +0000)
http://pyinsci.blogspot.com/2007/07/fastest-python-database-interface.html

test/perf/insertspeed.py [new file with mode: 0644]

diff --git a/test/perf/insertspeed.py b/test/perf/insertspeed.py
new file mode 100644 (file)
index 0000000..ed36369
--- /dev/null
@@ -0,0 +1,31 @@
+import testbase
+from sqlalchemy import *
+from sqlalchemy.orm import *
+from testlib import *
+
+
+db = create_engine('sqlite://')
+metadata = MetaData(db)
+Person_table = Table('Person', metadata,
+    Column('name', String(40)),
+    Column('sex', Integer),
+    Column('age', Integer))
+
+@profiling.profiled('test_many_inserts', always=True)
+def test_many_inserts(n):
+    print "Inserting %s records into SQLite(memory) with SQLAlchemy"%n
+    i = Person_table.insert()
+    i.execute([{'name':'John Doe','sex':1,'age':35} for j in xrange(n)])
+    s = Person_table.select()
+    r = s.execute()
+    print "Number of records selected: %s\n"%(len(r.fetchall()))
+
+def all():
+    metadata.create_all()
+    try:
+        test_many_inserts(100000)
+    finally:
+        metadata.drop_all()
+
+if __name__ == '__main__':
+    all()