FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

add db cleanup for PyPy by mattip · Pull Request #472 · python/pyperformance · GitHub

Repository navigation

Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,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 @@ -59,29 +58,30 @@ def bench_sqlalchemy(loops, npeople):
total_dt = 0.0

for loops in range(loops):
with DBSession() as session:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

cool. does it work / fix the problem? this "with" syntax for the session was introduced probably long after this test suite was written

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yes, this fixes the warning/crash.

# drop rows created by the previous benchmark
session.query(Person).delete(synchronize_session=False)
session.query(Address).delete(synchronize_session=False)
session.query(Person).delete(synchronize_session=False)
session.query(Address).delete(synchronize_session=False)

# Run the benchmark once
t0 = pyperf.perf_counter()
# 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()
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()
# 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()
# do 100 queries per insert
for i in range(npeople):
session.query(Person).all()

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

return total_dt

Expand Down
Loading

Back | FazBrowse Home | New Git URL