~divmod-dev/divmod.org/nevow-declare-twisted-dep-2629

« back to all changes in this revision

Viewing changes to Axiom/benchmark/benchlib.py

  • Committer: exarkun
  • Date: 2009-05-14 13:33:33 UTC
  • Revision ID: svn-v4:866e43f7-fbfc-0310-8f2a-ec88d1da2979:trunk:17278
Merge optimize-setattr-2793-2

Author: exarkun
Reviewer: washort, glyph
Fixes: #2793

Speed up setting attributes on Item instances by caching
descriptor setter methods on their first use so that they
can later be found against with a dictionary lookup instead
of an mro traversal.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
 
11
11
typeNameCounter = count(0).next
12
12
 
13
 
def itemTypeWithSomeAttributes(numAttributes):
 
13
def itemTypeWithSomeAttributes(attributeTypes):
14
14
    """
15
15
    Create a new L{Item} subclass with L{numAttributes} integers in its
16
16
    schema.
17
17
    """
18
18
    class SomeItem(Item):
19
19
        typeName = 'someitem_' + str(typeNameCounter())
20
 
        for i in xrange(numAttributes):
21
 
            locals()['attr_' + str(i)] = integer()
 
20
        for i, attributeType in enumerate(attributeTypes):
 
21
            locals()['attr_' + str(i)] = attributeType()
22
22
    return SomeItem
23
23
 
24
24