summaryrefslogtreecommitdiff
path: root/test/perf
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-12-19 15:59:55 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2021-12-21 12:20:04 -0500
commite6cd36fc51d25922f20aa203229a636f5d6daabe (patch)
tree661a3bbeb6ee5cbbe1f8d40aae6951d8cef12b80 /test/perf
parentb301dd2d20f2da66f4eb69527ba2642da34c630d (diff)
downloadsqlalchemy-e6cd36fc51d25922f20aa203229a636f5d6daabe.tar.gz
implement cython for cache_anon_map, prefix_anon_map
These are small bits where cache_anon_map in particular is part of the cache key generation scheme which is a key target for cython. changing such a tiny element of the cache key gen is doing basically nothing yet, as the cython impl is mostly the exact same speed as the python one. I guess for cython to be effective we'd need to redo the whole cache key generation and possibly not use the same kinds of structures, which might not be very easy to do. Additionally, some cython runtime import errors are being observed on jenkins, add an upfront check to the test suite to indicate if the expected build succeeded when REQUIRE_SQLALCHEMY_CEXT is set. Running case CacheAnonMap Running python .... Done Running cython .... Done | python | cython | cy / py | test_get_anon_non_present| 0.301266758 | 0.231203834 | 0.767438915 | test_get_anon_present| 0.300919362 | 0.227336695 | 0.755473803 | test_has_key_non_present| 0.152725077 | 0.133191719 | 0.872101171 | test_has_key_present| 0.152689778 | 0.133673095 | 0.875455428 | Running case PrefixAnonMap Running python .. Done Running cython .. Done | python | cython | cy / py | test_apply_non_present| 0.358715744 | 0.335245703 | 0.934572034 | test_apply_present | 0.354434996 | 0.338579782 | 0.955266229 | Change-Id: I0d3f1dd285c044afc234479141d831b2ee0455be
Diffstat (limited to 'test/perf')
-rw-r--r--test/perf/compiled_extensions.py90
1 files changed, 90 insertions, 0 deletions
diff --git a/test/perf/compiled_extensions.py b/test/perf/compiled_extensions.py
index b9bb9ebd2..14b8ed693 100644
--- a/test/perf/compiled_extensions.py
+++ b/test/perf/compiled_extensions.py
@@ -994,6 +994,96 @@ class BaseRow(Case):
self.row_long.y
+class CacheAnonMap(Case):
+ @staticmethod
+ def python():
+ from sqlalchemy.sql._py_util import cache_anon_map
+
+ return cache_anon_map
+
+ @staticmethod
+ def cython():
+ from sqlalchemy.cyextension.util import cache_anon_map
+
+ return cache_anon_map
+
+ IMPLEMENTATIONS = {"python": python.__func__, "cython": cython.__func__}
+
+ NUMBER = 1000000
+
+ def init_objects(self):
+ from sqlalchemy import column, bindparam
+
+ self.object_1 = column("x")
+ self.object_2 = bindparam("y")
+
+ self.impl_w_non_present = self.impl()
+ self.impl_w_present = iwp = self.impl()
+ iwp.get_anon(self.object_1)
+ iwp.get_anon(self.object_2)
+
+ @classmethod
+ def update_results(cls, results):
+ cls._divide_results(results, "cython", "python", "cy / py")
+
+ @test_case
+ def test_get_anon_non_present(self):
+ self.impl_w_non_present.get_anon(self.object_1)
+
+ @test_case
+ def test_get_anon_present(self):
+ self.impl_w_present.get_anon(self.object_1)
+
+ @test_case
+ def test_has_key_non_present(self):
+ id(self.object_1) in self.impl_w_non_present
+
+ @test_case
+ def test_has_key_present(self):
+ id(self.object_1) in self.impl_w_present
+
+
+class PrefixAnonMap(Case):
+ @staticmethod
+ def python():
+ from sqlalchemy.sql._py_util import prefix_anon_map
+
+ return prefix_anon_map
+
+ @staticmethod
+ def cython():
+ from sqlalchemy.cyextension.util import prefix_anon_map
+
+ return prefix_anon_map
+
+ IMPLEMENTATIONS = {"python": python.__func__, "cython": cython.__func__}
+
+ NUMBER = 1000000
+
+ def init_objects(self):
+ from sqlalchemy.sql.elements import _anonymous_label
+
+ self.name = _anonymous_label.safe_construct(58243, "some_column_name")
+
+ self.impl_w_non_present = self.impl()
+ self.impl_w_present = iwp = self.impl()
+ self.name.apply_map(iwp)
+
+ @classmethod
+ def update_results(cls, results):
+ cls._divide_results(results, "cython", "python", "cy / py")
+
+ @test_case
+ def test_apply_non_present(self):
+
+ self.name.apply_map(self.impl_w_non_present)
+
+ @test_case
+ def test_apply_present(self):
+
+ self.name.apply_map(self.impl_w_present)
+
+
def tabulate(results, inverse):
dim = 11
header = "{:<20}|" + (" {:<%s} |" % dim) * len(results)