summaryrefslogtreecommitdiff
path: root/examples/performance/short_selects.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-01-06 01:14:26 -0500
committermike bayer <mike_mp@zzzcomputing.com>2019-01-06 17:34:50 +0000
commit1e1a38e7801f410f244e4bbb44ec795ae152e04e (patch)
tree28e725c5c8188bd0cfd133d1e268dbca9b524978 /examples/performance/short_selects.py
parent404e69426b05a82d905cbb3ad33adafccddb00dd (diff)
downloadsqlalchemy-1e1a38e7801f410f244e4bbb44ec795ae152e04e.tar.gz
Run black -l 79 against all source files
This is a straight reformat run using black as is, with no edits applied at all. The black run will format code consistently, however in some cases that are prevalent in SQLAlchemy code it produces too-long lines. The too-long lines will be resolved in the following commit that will resolve all remaining flake8 issues including shadowed builtins, long lines, import order, unused imports, duplicate imports, and docstring issues. Change-Id: I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9
Diffstat (limited to 'examples/performance/short_selects.py')
-rw-r--r--examples/performance/short_selects.py60
1 files changed, 36 insertions, 24 deletions
diff --git a/examples/performance/short_selects.py b/examples/performance/short_selects.py
index 6f64aa63e..4a8d401ad 100644
--- a/examples/performance/short_selects.py
+++ b/examples/performance/short_selects.py
@@ -6,8 +6,14 @@ record by primary key
from . import Profiler
from sqlalchemy.ext.declarative import declarative_base
-from sqlalchemy import Column, Integer, String, create_engine, \
- bindparam, select
+from sqlalchemy import (
+ Column,
+ Integer,
+ String,
+ create_engine,
+ bindparam,
+ select,
+)
from sqlalchemy.orm import Session, deferred
from sqlalchemy.ext import baked
import random
@@ -29,6 +35,7 @@ class Customer(Base):
y = deferred(Column(Integer))
z = deferred(Column(Integer))
+
Profiler.init("short_selects", num=10000)
@@ -39,16 +46,20 @@ def setup_database(dburl, echo, num):
Base.metadata.drop_all(engine)
Base.metadata.create_all(engine)
sess = Session(engine)
- sess.add_all([
- Customer(
- id=i, name='c%d' % i, description="c%d" % i,
- q=i * 10,
- p=i * 20,
- x=i * 30,
- y=i * 40,
- )
- for i in ids
- ])
+ sess.add_all(
+ [
+ Customer(
+ id=i,
+ name="c%d" % i,
+ description="c%d" % i,
+ q=i * 10,
+ p=i * 20,
+ x=i * 30,
+ y=i * 40,
+ )
+ for i in ids
+ ]
+ )
sess.commit()
@@ -65,9 +76,9 @@ def test_orm_query_cols_only(n):
"""test an ORM query of only the entity columns."""
session = Session(bind=engine)
for id_ in random.sample(ids, n):
- session.query(
- Customer.id, Customer.name, Customer.description
- ).filter(Customer.id == id_).one()
+ session.query(Customer.id, Customer.name, Customer.description).filter(
+ Customer.id == id_
+ ).one()
@Profiler.profile
@@ -77,7 +88,7 @@ def test_baked_query(n):
s = Session(bind=engine)
for id_ in random.sample(ids, n):
q = bakery(lambda s: s.query(Customer))
- q += lambda q: q.filter(Customer.id == bindparam('id'))
+ q += lambda q: q.filter(Customer.id == bindparam("id"))
q(s).params(id=id_).one()
@@ -88,9 +99,9 @@ def test_baked_query_cols_only(n):
s = Session(bind=engine)
for id_ in random.sample(ids, n):
q = bakery(
- lambda s: s.query(
- Customer.id, Customer.name, Customer.description))
- q += lambda q: q.filter(Customer.id == bindparam('id'))
+ lambda s: s.query(Customer.id, Customer.name, Customer.description)
+ )
+ q += lambda q: q.filter(Customer.id == bindparam("id"))
q(s).params(id=id_).one()
@@ -109,7 +120,7 @@ def test_core_new_stmt_each_time(n):
def test_core_reuse_stmt(n):
"""test core, reusing the same statement (but recompiling each time)."""
- stmt = select([Customer.__table__]).where(Customer.id == bindparam('id'))
+ stmt = select([Customer.__table__]).where(Customer.id == bindparam("id"))
with engine.connect() as conn:
for id_ in random.sample(ids, n):
@@ -122,13 +133,14 @@ def test_core_reuse_stmt_compiled_cache(n):
"""test core, reusing the same statement + compiled cache."""
compiled_cache = {}
- stmt = select([Customer.__table__]).where(Customer.id == bindparam('id'))
- with engine.connect().\
- execution_options(compiled_cache=compiled_cache) as conn:
+ stmt = select([Customer.__table__]).where(Customer.id == bindparam("id"))
+ with engine.connect().execution_options(
+ compiled_cache=compiled_cache
+ ) as conn:
for id_ in random.sample(ids, n):
row = conn.execute(stmt, id=id_).first()
tuple(row)
-if __name__ == '__main__':
+if __name__ == "__main__":
Profiler.main()