Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class Address(Base):
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()


# add 'npeople' people to the database
Expand All @@ -53,29 +52,30 @@ def bench_sqlalchemy(loops, npeople):
total_dt = 0.0

for loops in range(loops):
# drop rows created by the previous benchmark
session.query(Person).delete(synchronize_session=False)
session.query(Address).delete(synchronize_session=False)

# Run the benchmark once
t0 = pyperf.perf_counter()

for i in range(npeople):
# Insert a Person in the person table
new_person = Person(name="name %i" % i)
session.add(new_person)
session.commit()

# Insert an Address in the address table
new_address = Address(post_code='%05i' % i, person=new_person)
session.add(new_address)
session.commit()

# do 100 queries per insert
for i in range(npeople):
session.query(Person).all()

total_dt += (pyperf.perf_counter() - t0)
with DBSession() as session:
Comment thread
StanFromIreland marked this conversation as resolved.
Resolved
# drop rows created by the previous benchmark
session.query(Person).delete(synchronize_session=False)
session.query(Address).delete(synchronize_session=False)

# Run the benchmark once
t0 = pyperf.perf_counter()

for i in range(npeople):
# Insert a Person in the person table
new_person = Person(name="name %i" % i)
session.add(new_person)
session.commit()

# Insert an Address in the address table
new_address = Address(post_code='%05i' % i, person=new_person)
session.add(new_address)
session.commit()

# do 100 queries per insert
for i in range(npeople):
session.query(Person).all()

total_dt += (pyperf.perf_counter() - t0)

return total_dt

Expand Down
Loading