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

« back to all changes in this revision

Viewing changes to Axiom/benchmark/inmemory-setting

  • 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:
 
1
#!/usr/bin/python
 
2
 
 
3
# Benchmark of Axiom Item in-memory attribute modification.  Accepts no
 
4
# parameters. Reports one statistic, the number of seconds it takes to
 
5
# change the value of an in-memory attribute.
 
6
 
 
7
 
 
8
import sys, time
 
9
 
 
10
from axiom.store import Store
 
11
from axiom.attributes import inmemory, text
 
12
 
 
13
import benchlib
 
14
 
 
15
 
 
16
def benchmark():
 
17
    numAttributes = 5
 
18
    # Include text attribute because at least one persistent attribute is required.
 
19
    SomeItem = benchlib.itemTypeWithSomeAttributes([inmemory] * numAttributes + [text])
 
20
 
 
21
    counter = range(10000)
 
22
    store = Store()
 
23
    items = []
 
24
    for i in counter:
 
25
        items.append(SomeItem(store=store))
 
26
 
 
27
    before = time.time()
 
28
    for i in items:
 
29
        i.attr_0 = 1
 
30
        i.attr_1 = 2
 
31
        i.attr_2 = 3
 
32
        i.attr_3 = 4
 
33
        i.attr_4 = 5
 
34
    after = time.time()
 
35
 
 
36
    return (after - before) / (len(counter) * numAttributes)
 
37
 
 
38
 
 
39
def main(argv):
 
40
    if len(argv) != 1:
 
41
        raise SystemExit("Usage: %s <number of attributes>")
 
42
    print benchmark()
 
43
 
 
44
 
 
45
if __name__ == '__main__':
 
46
    main(sys.argv)