Skip to content

Commit 1281b50

Browse files
committed
- update the test times, include pypy, clean up the script
1 parent 9059df8 commit 1281b50

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

doc/build/faq.rst

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -620,12 +620,21 @@ is competitive with using the raw database API directly.
620620

621621
The example below illustrates time-based tests for four different
622622
methods of inserting rows, going from the most automated to the least.
623-
Runtimes observed here are:
623+
With cPython 2.7, runtimes observed::
624624

625-
* SQLAlchemy ORM: Total time for 100000 records 16.4133379459 secs
626-
* SQLAlchemy ORM pk given: Total time for 100000 records 9.77570986748 secs
627-
* SQLAlchemy Core: Total time for 100000 records 0.568737983704 secs
628-
* sqlite3: Total time for 100000 records 0.595796823502 sec
625+
classics-MacBook-Pro:sqlalchemy classic$ python test.py
626+
SQLAlchemy ORM: Total time for 100000 records 14.3528850079 secs
627+
SQLAlchemy ORM pk given: Total time for 100000 records 10.0164160728 secs
628+
SQLAlchemy Core: Total time for 100000 records 0.775382995605 secs
629+
sqlite3: Total time for 100000 records 0.676795005798 sec
630+
631+
We can reduce the time by a factor of three using recent versions of `Pypy <http://pypy.org/>`_::
632+
633+
classics-MacBook-Pro:sqlalchemy classic$ /usr/local/src/pypy-2.1-beta2-osx64/bin/pypy test.py
634+
SQLAlchemy ORM: Total time for 100000 records 5.88369488716 secs
635+
SQLAlchemy ORM pk given: Total time for 100000 records 3.52294301987 secs
636+
SQLAlchemy Core: Total time for 100000 records 0.613556146622 secs
637+
sqlite3: Total time for 100000 records 0.442467927933 sec
629638

630639
Script::
631640

@@ -638,13 +647,14 @@ Script::
638647

639648
Base = declarative_base()
640649
DBSession = scoped_session(sessionmaker())
650+
engine = None
641651

642652
class Customer(Base):
643653
__tablename__ = "customer"
644654
id = Column(Integer, primary_key=True)
645655
name = Column(String(255))
646656

647-
def init_sqlalchemy(dbname = 'sqlite:///sqlalchemy.db'):
657+
def init_sqlalchemy(dbname='sqlite:///sqlalchemy.db'):
648658
global engine
649659
engine = create_engine(dbname, echo=False)
650660
DBSession.remove()
@@ -663,7 +673,7 @@ Script::
663673
DBSession.flush()
664674
DBSession.commit()
665675
print("SQLAlchemy ORM: Total time for " + str(n) +
666-
" records " + str(time.time() - t0) + " secs")
676+
" records " + str(time.time() - t0) + " secs")
667677

668678
def test_sqlalchemy_orm_pk_given(n=100000):
669679
init_sqlalchemy()
@@ -674,47 +684,47 @@ Script::
674684
if i % 1000 == 0:
675685
DBSession.flush()
676686
DBSession.commit()
677-
print(
678-
"SQLAlchemy ORM pk given: Total time for " + str(n) +
679-
" records " + str(time.time() - t0) + " secs")
687+
print("SQLAlchemy ORM pk given: Total time for " + str(n) +
688+
" records " + str(time.time() - t0) + " secs")
680689

681690
def test_sqlalchemy_core(n=100000):
682691
init_sqlalchemy()
683692
t0 = time.time()
684693
engine.execute(
685694
Customer.__table__.insert(),
686-
[{"name":'NAME ' + str(i)} for i in range(n)]
695+
[{"name": 'NAME ' + str(i)} for i in range(n)]
687696
)
688-
print(
689-
"SQLAlchemy Core: Total time for " + str(n) +
690-
" records " + str(time.time() - t0) + " secs")
697+
print("SQLAlchemy Core: Total time for " + str(n) +
698+
" records " + str(time.time() - t0) + " secs")
691699

692700
def init_sqlite3(dbname):
693701
conn = sqlite3.connect(dbname)
694702
c = conn.cursor()
695703
c.execute("DROP TABLE IF EXISTS customer")
696704
c.execute("CREATE TABLE customer (id INTEGER NOT NULL, "
697-
"name VARCHAR(255), PRIMARY KEY(id))")
705+
"name VARCHAR(255), PRIMARY KEY(id))")
698706
conn.commit()
699707
return conn
700708

701-
def test_sqlite3(n=100000, dbname = 'sqlite3.db'):
709+
def test_sqlite3(n=100000, dbname='sqlite3.db'):
702710
conn = init_sqlite3(dbname)
703711
c = conn.cursor()
704712
t0 = time.time()
705713
for i in range(n):
706714
row = ('NAME ' + str(i),)
707715
c.execute("INSERT INTO customer (name) VALUES (?)", row)
708716
conn.commit()
709-
print(
710-
"sqlite3: Total time for " + str(n) +
711-
" records " + str(time.time() - t0) + " sec")
717+
print("sqlite3: Total time for " + str(n) +
718+
" records " + str(time.time() - t0) + " sec")
712719

713720
if __name__ == '__main__':
714721
test_sqlalchemy_orm(100000)
715722
test_sqlalchemy_orm_pk_given(100000)
716723
test_sqlalchemy_core(100000)
717724
test_sqlite3(100000)
725+
726+
727+
718728
How do I make a Query that always adds a certain filter to every query?
719729
------------------------------------------------------------------------------------------------
720730

0 commit comments

Comments
 (0)