didn't match. use straight memoized_props here for now, add a perf test to check it
self.op = op
self.parent_token = self.impl.parent_token
- @classmethod
- def _token_gen(self, op):
- @util.memoized_property
- def gen(self):
- return Event(self, op)
- return gen
@property
def key(self):
state._modified_event(dict_, self, old)
dict_[self.key] = value
- _replace_token = _append_token = Event._token_gen(OP_REPLACE)
- _remove_token = Event._token_gen(OP_REMOVE)
+ @util.memoized_property
+ def _replace_token(self):
+ return Event(self, OP_REPLACE)
+
+ @util.memoized_property
+ def _append_token(self):
+ return Event(self, OP_REPLACE)
+
+ @util.memoized_property
+ def _remove_token(self):
+ return Event(self, OP_REMOVE)
def fire_replace_event(self, state, dict_, value, previous, initiator):
for fn in self.dispatch.set:
return [(instance_state(o), o) for o in current]
- _append_token = Event._token_gen(OP_APPEND)
- _remove_token = Event._token_gen(OP_REMOVE)
+ @util.memoized_property
+ def _append_token(self):
+ return Event(self, OP_APPEND)
+
+ @util.memoized_property
+ def _remove_token(self):
+ return Event(self, OP_REMOVE)
def fire_append_event(self, state, dict_, value, initiator):
for fn in self.dispatch.append:
history = self._get_collection_history(state, passive)
return history.added_plus_unchanged
- _append_token = attributes.Event._token_gen(attributes.OP_APPEND)
- _remove_token = attributes.Event._token_gen(attributes.OP_REMOVE)
+ @util.memoized_property
+ def _append_token(self):
+ return attributes.Event(self, attributes.OP_APPEND)
+
+ @util.memoized_property
+ def _remove_token(self):
+ return attributes.Event(self, attributes.OP_REMOVE)
def fire_append_event(self, state, dict_, value, initiator,
collection_history=None):
*[defer(letter) for letter in ['x', 'y', 'z', 'p', 'q', 'r']]).\
all()
+
+class AttributeOverheadTest(fixtures.MappedTest):
+ @classmethod
+ def define_tables(cls, metadata):
+ Table('parent', metadata, Column('id', Integer,
+ primary_key=True,
+ test_needs_autoincrement=True), Column('data',
+ String(20)))
+ Table('child', metadata, Column('id', Integer,
+ primary_key=True, test_needs_autoincrement=True),
+ Column('data', String(20)), Column('parent_id',
+ Integer, ForeignKey('parent.id'), nullable=False))
+
+ @classmethod
+ def setup_classes(cls):
+ class Parent(cls.Basic):
+ pass
+
+ class Child(cls.Basic):
+ pass
+
+ @classmethod
+ def setup_mappers(cls):
+ Child, Parent, parent, child = (cls.classes.Child,
+ cls.classes.Parent,
+ cls.tables.parent,
+ cls.tables.child)
+
+ mapper(Parent, parent, properties={'children':
+ relationship(Child, backref='parent')})
+ mapper(Child, child)
+
+
+ def test_attribute_set(self):
+ Parent, Child = self.classes.Parent, self.classes.Child
+ p1 = Parent()
+ c1 = Child()
+
+ @profiling.function_call_count()
+ def go():
+ for i in range(30):
+ c1.parent = p1
+ c1.parent = None
+ c1.parent = p1
+ del c1.parent
+ go()
+
+ def test_collection_append_remove(self):
+ Parent, Child = self.classes.Parent, self.classes.Child
+ p1 = Parent()
+ children = [Child() for i in range(100)]
+
+ @profiling.function_call_count()
+ def go():
+ for child in children:
+ p1.children.append(child)
+ for child in children:
+ p1.children.remove(child)
+ go()
+
sess.commit()
status("Associated grunts w/ bosses and committed")
-
# do some heavier reading
- for i in range(5):
+ for i in range(int(round(factor / 2.0))):
status("Heavy query run #%d" % (i + 1))
report = []
#stats.sort_stats('time', 'calls')
#stats.print_stats()
- #os.system("runsnake %s" % filename)
+# os.system("runsnake %s" % filename)
# SQLA Version: 0.7b1
# Total calls 4956750
runit(status, 10)
print("Total time: %d" % (time.time() - now))
-run_with_time()
+run_with_profile()
+#run_with_time()
test.aaa_profiling.test_compiler.CompileTest.test_update_whereclause 3.3_postgresql_psycopg2_nocextensions 151
test.aaa_profiling.test_compiler.CompileTest.test_update_whereclause 3.3_sqlite_pysqlite_cextensions 151
+# TEST: test.aaa_profiling.test_orm.AttributeOverheadTest.test_attribute_set
+
+test.aaa_profiling.test_orm.AttributeOverheadTest.test_attribute_set 2.7_sqlite_pysqlite_cextensions 4265
+
+# TEST: test.aaa_profiling.test_orm.AttributeOverheadTest.test_collection_append_remove
+
+test.aaa_profiling.test_orm.AttributeOverheadTest.test_collection_append_remove 2.7_sqlite_pysqlite_cextensions 6525
+
# TEST: test.aaa_profiling.test_orm.DeferOptionsTest.test_baseline
test.aaa_profiling.test_orm.DeferOptionsTest.test_baseline 2.7_mysql_mysqldb_cextensions 30052