summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-03-11 20:22:42 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2015-03-11 20:31:11 -0400
commite3b46bd62405b6ff57119e164718118f3e3565e0 (patch)
tree0f742a7c4a59490778b198396c66066bc2beb122 /examples
parentb815e9483319b93f98bef11c7d47378441f78d21 (diff)
downloadsqlalchemy-e3b46bd62405b6ff57119e164718118f3e3565e0.tar.gz
- Added a new extension suite :mod:`sqlalchemy.ext.baked`. This
simple but unusual system allows for a dramatic savings in Python overhead for the construction and processing of orm :class:`.Query` objects, from query construction up through rendering of a string SQL statement. fixes #3054
Diffstat (limited to 'examples')
-rw-r--r--examples/performance/__init__.py2
-rw-r--r--examples/performance/short_selects.py25
2 files changed, 26 insertions, 1 deletions
diff --git a/examples/performance/__init__.py b/examples/performance/__init__.py
index 88ae9b7dc..6264ae9f7 100644
--- a/examples/performance/__init__.py
+++ b/examples/performance/__init__.py
@@ -6,7 +6,7 @@ profile and associated implications:
* bulk inserts
* individual inserts, with or without transactions
* fetching large numbers of rows
-* running lots of small queries (TODO)
+* running lots of short queries
All suites include a variety of use patterns illustrating both Core
and ORM use, and are generally sorted in order of performance from worst
diff --git a/examples/performance/short_selects.py b/examples/performance/short_selects.py
index 333fb9632..ef1fcff4a 100644
--- a/examples/performance/short_selects.py
+++ b/examples/performance/short_selects.py
@@ -9,6 +9,7 @@ from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, create_engine, \
bindparam, select
from sqlalchemy.orm import Session, deferred
+from sqlalchemy.ext import baked
import random
Base = declarative_base()
@@ -70,6 +71,30 @@ def test_orm_query_cols_only(n):
@Profiler.profile
+def test_baked_query(n):
+ """test a baked query of the full entity."""
+ bakery = baked.bakery()
+ 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(s).params(id=id_).one()
+
+
+@Profiler.profile
+def test_baked_query_cols_only(n):
+ """test a baked query of only the entity columns."""
+ bakery = baked.bakery()
+ 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'))
+ q(s).params(id=id_).one()
+
+
+@Profiler.profile
def test_core_new_stmt_each_time(n):
"""test core, creating a new statement each time."""