From b05c8a0ef8b6e7bfd169a21e7c1f834fdb00da19 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 1 Jun 2020 16:26:41 -0400 Subject: [PATCH] Add a test / comment about test_orm_query Change-Id: I8d78b3e75127141da177f711fd91216391a3c859 --- examples/performance/short_selects.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/examples/performance/short_selects.py b/examples/performance/short_selects.py index 2f2b19c17d..64d9b05516 100644 --- a/examples/performance/short_selects.py +++ b/examples/performance/short_selects.py @@ -75,6 +75,25 @@ def test_orm_query(n): session.query(Customer).filter(Customer.id == id_).one() +@Profiler.profile +def test_orm_query_newstyle(n): + """test a straight ORM query of the full entity.""" + + # the newstyle query is faster for the following reasons: + # 1. it uses LABEL_STYLE_DISAMBIGUATE_ONLY, which saves on a huge amount + # of label generation and compilation calls + # 2. it does not use the Query @_assertions decorators. + + # however, both test_orm_query and test_orm_query_newstyle are still + # 25-30% slower than the full blown Query version in 1.3.x and this + # continues to be concerning. + + session = Session(bind=engine) + for id_ in random.sample(ids, n): + stmt = future_select(Customer).where(Customer.id == id_) + session.execute(stmt).scalars().unique().one() + + @Profiler.profile def test_orm_query_cols_only(n): """test an ORM query of only the entity columns.""" -- 2.39.5