forked from pypingou/kittybenchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
280 lines (223 loc) · 9.32 KB
/
tests.py
File metadata and controls
280 lines (223 loc) · 9.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# -*- coding: utf-8 -*-
import datetime
from pprint import pprint
import time
from kittystore.kittysastore import KittySAStore
from kittystore.mongostore import KittyMGStore
# Define global constant
TABLE = 'devel'
REP = 30
URL = 'postgres://mm3:mm3@localhost/mm3'
def db_store_factory():
return KittySAStore(URL)
def mg_store_factory():
return KittyMGStore(host='localhost', port=27017)
START = datetime.datetime(2012, 3, 1)
END = datetime.datetime(2012, 3, 30)
# store the results in a global variable
results = {}
def row(values):
return '\t'.join(['%s' % v for v in values]) + '\n'
def output(testname, results):
keys = sorted(results.keys())
value_lists = [results[key] for key in keys]
if len(set([len(value_list) for value_list in value_lists])) != 1:
print 'Something went wrong. No output.'
return
stream = open(testname, 'w')
stream.write(row(keys))
# skip the first value in the round
for zipped_values in zip(*value_lists)[1:]:
stream.write(row(zipped_values))
stream.close()
def run(testname, variant, rep, factory, funcname, *args, **kwargs):
print variant
testresults = results.setdefault(testname, {})
if variant in testresults:
print 'error, key already in results'
pprint(testresults)
return
testresults[variant] = []
retval = None
for i in range(0, rep):
store = factory()
start = time.time()
try:
retval = getattr(store, funcname)(*args, **kwargs)
except NotImplementedError:
del testresults[variant]
raise
testresults[variant].append(time.time() - start)
if hasattr(store, 'engine'):
# cleanup sqlalchemy connections
store.engine.dispose()
del store.engine
del store
return retval
def hashable(value):
if isinstance(value, dict):
val = []
for (key, value) in value.items():
val.append((hashable(key), hashable(value)))
return tuple(val)
elif isinstance(value, list):
valuelist = [hashable(v) for v in value]
return tuple(valuelist)
else:
return value
def run_tests(testname, rep, tests, *args, **kwargs):
print testname
test_key_func = kwargs.pop('test_key_func', None)
retvals = []
for (variant, factory, funcname) in tests:
try:
retval = run(testname, variant, rep, factory, funcname,
*args, **kwargs)
except NotImplementedError:
print 'Skipped.'
continue
if test_key_func is not None:
retvals.append(hashable(test_key_func(retval)))
else:
retvals.append(retval)
output(testname, results[testname])
if test_key_func is None:
return retvals
names = [test[0] for test in tests]
if len(set(retvals)) != 1:
print '** Results differs'
for (name, retval) in zip(names, retvals):
print '{name}: {retval}'.format(name=name,
retval=retval)
def get_email(rep):
(res_pg, res_mg) = run_tests('get_email', rep,
[['PG', db_store_factory, 'get_email'],
['MG', mg_store_factory, 'get_email']],
TABLE, '3D97B04F.7090405@terra.com.br',
test_key_func=None)
if res_mg['Subject'] != res_pg.subject and res_mg['Date'] != res_pg.date:
print '** Results differs'
print 'MG: %s' % res_mg
print 'PG: %s\n' % res_pg
def get_archives_range(rep):
run_tests('get_archives_range', rep,
[['PG', db_store_factory, 'get_archives'],
['MG', mg_store_factory, 'get_archives']],
TABLE, START, END,
test_key_func=len)
def first_email_in_archives_range(rep):
(res_pg, res_mg) = run_tests('first_email_in_archives_range', rep,
[['PG', db_store_factory, 'get_archives'],
['MG', mg_store_factory, 'get_archives']],
TABLE, START, END)
res_pg = res_pg[0]
res_mg = res_mg[0]
if res_mg['Subject'] != res_pg.subject and res_mg['Date'] != res_pg.date:
print '** Results differs'
print 'MG: %s' % res_mg
print 'PG: %s\n' % res_pg
def get_thread_length(rep):
run_tests('get_thread_length', rep,
[['PG', db_store_factory, 'get_thread_length'],
['MG', mg_store_factory, 'get_thread_length']],
TABLE, '4FCWUV6BCP3A5PASNFX6L5JOAE4GJ7F2',
test_key_func=lambda x: x)
def get_thread_participants(rep):
run_tests('get_thread_participants', rep,
[['PG', db_store_factory, 'get_thread_participants'],
['MG', mg_store_factory, 'get_thread_participants']],
TABLE, '4FCWUV6BCP3A5PASNFX6L5JOAE4GJ7F2',
test_key_func=len)
def get_archives_length(rep):
run_tests('get_archives_length', rep,
[['PG', db_store_factory, 'get_archives_length'],
['MG', mg_store_factory, 'get_archives_length']], TABLE,
test_key_func=lambda x: x)
def search_subject(rep):
run_tests('search_subject', rep,
[['PG-CS', db_store_factory, 'search_subject'],
['PG-IN', db_store_factory, 'search_subject_index'],
['MG-CS', mg_store_factory, 'search_subject']],
TABLE, 'rawhid',
test_key_func=len)
def search_subject_cs(rep):
run_tests('search_subject_cs', rep,
[['PG-CS', db_store_factory, 'search_subject_cs'],
['MG-CS', mg_store_factory, 'search_subject_cs']],
TABLE, 'rawhid',
test_key_func=len)
def search_content(rep):
run_tests('search_content', rep,
[['PG', db_store_factory, 'search_content'],
['PG-IN', db_store_factory, 'search_content_index'],
['MG', mg_store_factory, 'search_content']], TABLE, 'rawhid',
test_key_func=len)
def search_content_cs(rep):
run_tests('search_content_cs', rep,
[['PG', db_store_factory, 'search_content_cs'],
['MG', mg_store_factory, 'search_content_cs']], TABLE, 'rawhid',
test_key_func=len)
def search_content_subject(rep):
run_tests('search_content_subject', rep,
[['PG', db_store_factory, 'search_content_subject'],
['PG-OR', db_store_factory, 'search_content_subject_or'],
['PG-IN', db_store_factory, 'search_content_subject_index'],
['MG', mg_store_factory, 'search_content_subject']],
TABLE, 'rawhid', test_key_func=len)
def search_content_subject_300_30(rep):
run_tests('search_content_subject_300_30', rep,
[['PG', db_store_factory, 'search_content_subject'],
['PG-OR', db_store_factory, 'search_content_subject_or'],
['PG-IN', db_store_factory, 'search_content_subject_index'],
['MG', mg_store_factory, 'search_content_subject']],
TABLE, 'rawhid', limit=30, offset=300, test_key_func=len)
def search_content_subject_5000_30(rep):
run_tests('search_content_subject_5000_30', rep,
[['PG', db_store_factory, 'search_content_subject'],
['PG-OR', db_store_factory, 'search_content_subject_or'],
['PG-IN', db_store_factory, 'search_content_subject_index'],
['MG', mg_store_factory, 'search_content_subject']],
TABLE, 'rawhid', limit=30, offset=5000, test_key_func=len)
def search_content_subject_cs(rep):
run_tests('search_content_subject_cs', rep,
[['PG-CS', db_store_factory, 'search_content_subject_cs'],
['PG-OR-CS', db_store_factory, 'search_content_subject_or_cs'],
['MG-CS', mg_store_factory, 'search_content_subject_cs']],
TABLE, 'rawhid', test_key_func=len)
def search_sender(rep):
run_tests('search_sender', rep,
[['PG', db_store_factory, 'search_sender'],
['PG-OR', db_store_factory, 'search_sender_or'],
['MG', mg_store_factory, 'search_sender']],
TABLE, 'rawhid', test_key_func=len)
def search_sender_cs(rep):
run_tests('search_sender_cs', rep,
[['PG', db_store_factory, 'search_sender_cs'],
['PG-OR', db_store_factory, 'search_sender_or_cs'],
['MG', mg_store_factory, 'search_sender_cs']],
TABLE, 'rawhid', test_key_func=len)
def get_list_size(rep):
run_tests('get_list_size', rep,
[['PG', db_store_factory, 'get_list_size'],
['MG', mg_store_factory, 'get_list_size']],
TABLE, test_key_func=lambda x: x)
if __name__ == '__main__':
t_start = time.time()
get_email(REP)
get_archives_range(REP)
first_email_in_archives_range(REP)
get_thread_length(REP)
get_thread_participants(REP)
get_archives_length(REP)
search_subject(REP)
search_subject_cs(REP)
search_content(REP)
search_content_cs(REP)
search_content_subject(REP)
search_content_subject_300_30(REP)
search_content_subject_5000_30(REP)
search_content_subject_cs(REP)
search_sender(REP)
search_sender_cs(REP)
get_list_size(REP)
print "Ran for %s seconds" % (time.time() - t_start)