Premiere version : mise en route du suivi.
[auf_roundup.git] / test / benchmark.py
1 import sys, os, time
2
3 from roundup.hyperdb import String, Password, Link, Multilink, Date, \
4 Interval, DatabaseError, Boolean, Number
5 from roundup import date, password
6
7 from db_test_base import config
8
9 def setupSchema(db, module):
10 status = module.Class(db, "status", name=String())
11 status.setkey("name")
12 user = module.Class(db, "user", username=String(), password=Password(),
13 assignable=Boolean(), age=Number(), roles=String())
14 user.setkey("username")
15 file = module.FileClass(db, "file", name=String(), type=String(),
16 comment=String(indexme="yes"))
17 issue = module.IssueClass(db, "issue", title=String(indexme="yes"),
18 status=Link("status"), nosy=Multilink("user"), deadline=Date(),
19 foo=Interval(), files=Multilink("file"), assignedto=Link('user'))
20 session = module.Class(db, 'session', title=String())
21 session.disableJournalling()
22 db.post_init()
23 db.commit()
24
25 def main(backendname, time=time.time, numissues=10):
26 try:
27 exec('from roundup.backends import %s as backend'%backendname)
28 except ImportError:
29 return
30
31 times = []
32
33 config.DATABASE = os.path.join('_benchmark', '%s-%s'%(backendname,
34 numissues))
35 if not os.path.exists(config.DATABASE):
36 db = backend.Database(config, 'admin')
37 setupSchema(db, backend)
38 # create a whole bunch of stuff
39 db.user.create(**{'username': 'admin'})
40 db.status.create(name="unread")
41 db.status.create(name="in-progress")
42 db.status.create(name="testing")
43 db.status.create(name="resolved")
44 pc = -1
45 for i in range(numissues):
46 db.user.create(**{'username': 'user %s'%i})
47 for j in range(10):
48 db.user.set(str(i+1), assignable=1)
49 db.user.set(str(i+1), assignable=0)
50 db.issue.create(**{'title': 'issue %s'%i})
51 for j in range(10):
52 db.issue.set(str(i+1), status='2', assignedto='2', nosy=[])
53 db.issue.set(str(i+1), status='1', assignedto='1',
54 nosy=['1','2'])
55 if (i*100/numissues) != pc:
56 pc = (i*100/numissues)
57 sys.stdout.write("%d%%\r"%pc)
58 sys.stdout.flush()
59 db.commit()
60 else:
61 db = backend.Database(config, 'admin')
62 setupSchema(db, backend)
63
64 sys.stdout.write('%7s: %-6d'%(backendname, numissues))
65 sys.stdout.flush()
66
67 times.append(('start', time()))
68
69 # fetch
70 db.clearCache()
71 for i in db.issue.list():
72 db.issue.get(i, 'title')
73 times.append(('fetch', time()))
74
75 # journals
76 db.clearCache()
77 for i in db.issue.list():
78 db.issue.history(i)
79 times.append(('journal', time()))
80
81 # "calculated" props
82 db.clearCache()
83 for i in db.issue.list():
84 db.issue.get(i, 'activity')
85 db.issue.get(i, 'creator')
86 db.issue.get(i, 'creation')
87 times.append(('jprops', time()))
88
89 # lookup
90 db.clearCache()
91 for i in range(numissues):
92 db.user.lookup('user %s'%i)
93 times.append(('lookup', time()))
94
95 # filter
96 db.clearCache()
97 for i in range(100):
98 db.issue.filter(None, {'assignedto': '1', 'title':'issue'},
99 ('+', 'activity'), ('+', 'status'))
100 times.append(('filter', time()))
101
102 # filter with multilink
103 db.clearCache()
104 for i in range(100):
105 db.issue.filter(None, {'nosy': ['1'], 'assignedto': '1',
106 'title':'issue'}, ('+', 'activity'), ('+', 'status'))
107 times.append(('filtml', time()))
108
109 # results
110 last = None
111 for event, stamp in times:
112 if last is None:
113 first = stamp
114 else:
115 sys.stdout.write(' %-6.2f'%(stamp-last))
116 last = stamp
117 print ' %-6.2f'%(last-first)
118 sys.stdout.flush()
119
120 if __name__ == '__main__':
121 # 0 1 2 3 4 5 6
122 # 01234567890123456789012345678901234567890123456789012345678901234
123 print 'Test name fetch journl jprops lookup filter filtml TOTAL '
124 for name in 'anydbm metakit sqlite'.split():
125 main(name)
126 for name in 'anydbm metakit sqlite'.split():
127 main(name, numissues=20)
128 for name in 'anydbm metakit sqlite'.split():
129 main(name, numissues=100)
130 # don't even bother benchmarking the dbm backends > 100!
131 for name in 'metakit sqlite'.split():
132 main(name, numissues=1000)
133
134 # vim: set et sts=4 sw=4 :