blob: 207d88fcac89aaa7b1ee05f3625bca69509f2023 [file] [log] [blame]
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001from pybench import Test
2
3class DictCreation(Test):
4
5 version = 0.3
6 operations = 5*(5 + 5)
7 rounds = 60000
8
9 def test(self):
10
11 for i in xrange(self.rounds):
12
13 d1 = {}
14 d2 = {}
15 d3 = {}
16 d4 = {}
17 d5 = {}
18
19 d1 = {1:2,3:4,5:6}
20 d2 = {2:3,4:5,6:7}
21 d3 = {3:4,5:6,7:8}
22 d4 = {4:5,6:7,8:9}
23 d5 = {6:7,8:9,10:11}
24
25 d1 = {}
26 d2 = {}
27 d3 = {}
28 d4 = {}
29 d5 = {}
30
31 d1 = {1:2,3:4,5:6}
32 d2 = {2:3,4:5,6:7}
33 d3 = {3:4,5:6,7:8}
34 d4 = {4:5,6:7,8:9}
35 d5 = {6:7,8:9,10:11}
36
37 d1 = {}
38 d2 = {}
39 d3 = {}
40 d4 = {}
41 d5 = {}
42
43 d1 = {1:2,3:4,5:6}
44 d2 = {2:3,4:5,6:7}
45 d3 = {3:4,5:6,7:8}
46 d4 = {4:5,6:7,8:9}
47 d5 = {6:7,8:9,10:11}
48
49 d1 = {}
50 d2 = {}
51 d3 = {}
52 d4 = {}
53 d5 = {}
54
55 d1 = {1:2,3:4,5:6}
56 d2 = {2:3,4:5,6:7}
57 d3 = {3:4,5:6,7:8}
58 d4 = {4:5,6:7,8:9}
59 d5 = {6:7,8:9,10:11}
60
61 d1 = {}
62 d2 = {}
63 d3 = {}
64 d4 = {}
65 d5 = {}
66
67 d1 = {1:2,3:4,5:6}
68 d2 = {2:3,4:5,6:7}
69 d3 = {3:4,5:6,7:8}
70 d4 = {4:5,6:7,8:9}
71 d5 = {6:7,8:9,10:11}
72
73 def calibrate(self):
74
75 for i in xrange(self.rounds):
76 pass
77
78class DictWithStringKeys(Test):
79
80 version = 0.1
81 operations = 5*(6 + 6)
82 rounds = 200000
83
84 def test(self):
85
86 d = {}
87
88 for i in xrange(self.rounds):
89
90 d['abc'] = 1
91 d['def'] = 2
92 d['ghi'] = 3
93 d['jkl'] = 4
94 d['mno'] = 5
95 d['pqr'] = 6
96
97 d['abc']
98 d['def']
99 d['ghi']
100 d['jkl']
101 d['mno']
102 d['pqr']
103
104 d['abc'] = 1
105 d['def'] = 2
106 d['ghi'] = 3
107 d['jkl'] = 4
108 d['mno'] = 5
109 d['pqr'] = 6
110
111 d['abc']
112 d['def']
113 d['ghi']
114 d['jkl']
115 d['mno']
116 d['pqr']
117
118 d['abc'] = 1
119 d['def'] = 2
120 d['ghi'] = 3
121 d['jkl'] = 4
122 d['mno'] = 5
123 d['pqr'] = 6
124
125 d['abc']
126 d['def']
127 d['ghi']
128 d['jkl']
129 d['mno']
130 d['pqr']
131
132 d['abc'] = 1
133 d['def'] = 2
134 d['ghi'] = 3
135 d['jkl'] = 4
136 d['mno'] = 5
137 d['pqr'] = 6
138
139 d['abc']
140 d['def']
141 d['ghi']
142 d['jkl']
143 d['mno']
144 d['pqr']
145
146 d['abc'] = 1
147 d['def'] = 2
148 d['ghi'] = 3
149 d['jkl'] = 4
150 d['mno'] = 5
151 d['pqr'] = 6
152
153 d['abc']
154 d['def']
155 d['ghi']
156 d['jkl']
157 d['mno']
158 d['pqr']
159
160 def calibrate(self):
161
162 d = {}
163
164 for i in xrange(self.rounds):
165 pass
166
167class DictWithFloatKeys(Test):
168
169 version = 0.1
170 operations = 5*(6 + 6)
171 rounds = 200000
172
173 def test(self):
174
175 d = {}
176
177 for i in xrange(self.rounds):
178
179 d[1.234] = 1
180 d[2.345] = 2
181 d[3.456] = 3
182 d[4.567] = 4
183 d[5.678] = 5
184 d[6.789] = 6
185
186 d[1.234]
187 d[2.345]
188 d[3.456]
189 d[4.567]
190 d[5.678]
191 d[6.789]
192
193 d[1.234] = 1
194 d[2.345] = 2
195 d[3.456] = 3
196 d[4.567] = 4
197 d[5.678] = 5
198 d[6.789] = 6
199
200 d[1.234]
201 d[2.345]
202 d[3.456]
203 d[4.567]
204 d[5.678]
205 d[6.789]
206
207 d[1.234] = 1
208 d[2.345] = 2
209 d[3.456] = 3
210 d[4.567] = 4
211 d[5.678] = 5
212 d[6.789] = 6
213
214 d[1.234]
215 d[2.345]
216 d[3.456]
217 d[4.567]
218 d[5.678]
219 d[6.789]
220
221 d[1.234] = 1
222 d[2.345] = 2
223 d[3.456] = 3
224 d[4.567] = 4
225 d[5.678] = 5
226 d[6.789] = 6
227
228 d[1.234]
229 d[2.345]
230 d[3.456]
231 d[4.567]
232 d[5.678]
233 d[6.789]
234
235 d[1.234] = 1
236 d[2.345] = 2
237 d[3.456] = 3
238 d[4.567] = 4
239 d[5.678] = 5
240 d[6.789] = 6
241
242 d[1.234]
243 d[2.345]
244 d[3.456]
245 d[4.567]
246 d[5.678]
247 d[6.789]
248
249 def calibrate(self):
250
251 d = {}
252
253 for i in xrange(self.rounds):
254 pass
255
256class DictWithIntegerKeys(Test):
257
258 version = 0.1
259 operations = 5*(6 + 6)
260 rounds = 200000
261
262 def test(self):
263
264 d = {}
265
266 for i in xrange(self.rounds):
267
268 d[1] = 1
269 d[2] = 2
270 d[3] = 3
271 d[4] = 4
272 d[5] = 5
273 d[6] = 6
274
275 d[1]
276 d[2]
277 d[3]
278 d[4]
279 d[5]
280 d[6]
281
282 d[1] = 1
283 d[2] = 2
284 d[3] = 3
285 d[4] = 4
286 d[5] = 5
287 d[6] = 6
288
289 d[1]
290 d[2]
291 d[3]
292 d[4]
293 d[5]
294 d[6]
295
296 d[1] = 1
297 d[2] = 2
298 d[3] = 3
299 d[4] = 4
300 d[5] = 5
301 d[6] = 6
302
303 d[1]
304 d[2]
305 d[3]
306 d[4]
307 d[5]
308 d[6]
309
310 d[1] = 1
311 d[2] = 2
312 d[3] = 3
313 d[4] = 4
314 d[5] = 5
315 d[6] = 6
316
317 d[1]
318 d[2]
319 d[3]
320 d[4]
321 d[5]
322 d[6]
323
324 d[1] = 1
325 d[2] = 2
326 d[3] = 3
327 d[4] = 4
328 d[5] = 5
329 d[6] = 6
330
331 d[1]
332 d[2]
333 d[3]
334 d[4]
335 d[5]
336 d[6]
337
338 def calibrate(self):
339
340 d = {}
341
342 for i in xrange(self.rounds):
343 pass
344
345class SimpleDictManipulation(Test):
346
347 version = 0.3
348 operations = 5*(6 + 6 + 6 + 6)
349 rounds = 50000
350
351 def test(self):
352
353 d = {}
354
355 for i in xrange(self.rounds):
356
357 d[0] = 3
358 d[1] = 4
359 d[2] = 5
360 d[3] = 3
361 d[4] = 4
362 d[5] = 5
363
364 x = d[0]
365 x = d[1]
366 x = d[2]
367 x = d[3]
368 x = d[4]
369 x = d[5]
370
371 d.has_key(0)
372 d.has_key(2)
373 d.has_key(4)
374 d.has_key(6)
375 d.has_key(8)
376 d.has_key(10)
377
378 del d[0]
379 del d[1]
380 del d[2]
381 del d[3]
382 del d[4]
383 del d[5]
384
385 d[0] = 3
386 d[1] = 4
387 d[2] = 5
388 d[3] = 3
389 d[4] = 4
390 d[5] = 5
391
392 x = d[0]
393 x = d[1]
394 x = d[2]
395 x = d[3]
396 x = d[4]
397 x = d[5]
398
399 d.has_key(0)
400 d.has_key(2)
401 d.has_key(4)
402 d.has_key(6)
403 d.has_key(8)
404 d.has_key(10)
405
406 del d[0]
407 del d[1]
408 del d[2]
409 del d[3]
410 del d[4]
411 del d[5]
412
413 d[0] = 3
414 d[1] = 4
415 d[2] = 5
416 d[3] = 3
417 d[4] = 4
418 d[5] = 5
419
420 x = d[0]
421 x = d[1]
422 x = d[2]
423 x = d[3]
424 x = d[4]
425 x = d[5]
426
427 d.has_key(0)
428 d.has_key(2)
429 d.has_key(4)
430 d.has_key(6)
431 d.has_key(8)
432 d.has_key(10)
433
434 del d[0]
435 del d[1]
436 del d[2]
437 del d[3]
438 del d[4]
439 del d[5]
440
441 d[0] = 3
442 d[1] = 4
443 d[2] = 5
444 d[3] = 3
445 d[4] = 4
446 d[5] = 5
447
448 x = d[0]
449 x = d[1]
450 x = d[2]
451 x = d[3]
452 x = d[4]
453 x = d[5]
454
455 d.has_key(0)
456 d.has_key(2)
457 d.has_key(4)
458 d.has_key(6)
459 d.has_key(8)
460 d.has_key(10)
461
462 del d[0]
463 del d[1]
464 del d[2]
465 del d[3]
466 del d[4]
467 del d[5]
468
469 d[0] = 3
470 d[1] = 4
471 d[2] = 5
472 d[3] = 3
473 d[4] = 4
474 d[5] = 5
475
476 x = d[0]
477 x = d[1]
478 x = d[2]
479 x = d[3]
480 x = d[4]
481 x = d[5]
482
483 d.has_key(0)
484 d.has_key(2)
485 d.has_key(4)
486 d.has_key(6)
487 d.has_key(8)
488 d.has_key(10)
489
490 del d[0]
491 del d[1]
492 del d[2]
493 del d[3]
494 del d[4]
495 del d[5]
496
497 def calibrate(self):
498
499 d = {}
500
501 for i in xrange(self.rounds):
502 pass
503