move sections
[python/dscho.git] / Tools / pybench / Dict.py
blob9cdd6826440a9ef4a42cefb81b043f6ab51630af
1 from pybench import Test
3 class DictCreation(Test):
5 version = 2.0
6 operations = 5*(5 + 5)
7 rounds = 80000
9 def test(self):
11 for i in xrange(self.rounds):
13 d1 = {}
14 d2 = {}
15 d3 = {}
16 d4 = {}
17 d5 = {}
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}
25 d1 = {}
26 d2 = {}
27 d3 = {}
28 d4 = {}
29 d5 = {}
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}
37 d1 = {}
38 d2 = {}
39 d3 = {}
40 d4 = {}
41 d5 = {}
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}
49 d1 = {}
50 d2 = {}
51 d3 = {}
52 d4 = {}
53 d5 = {}
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}
61 d1 = {}
62 d2 = {}
63 d3 = {}
64 d4 = {}
65 d5 = {}
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}
73 def calibrate(self):
75 for i in xrange(self.rounds):
76 pass
78 class DictWithStringKeys(Test):
80 version = 2.0
81 operations = 5*(6 + 6)
82 rounds = 200000
84 def test(self):
86 d = {}
88 for i in xrange(self.rounds):
90 d['abc'] = 1
91 d['def'] = 2
92 d['ghi'] = 3
93 d['jkl'] = 4
94 d['mno'] = 5
95 d['pqr'] = 6
97 d['abc']
98 d['def']
99 d['ghi']
100 d['jkl']
101 d['mno']
102 d['pqr']
104 d['abc'] = 1
105 d['def'] = 2
106 d['ghi'] = 3
107 d['jkl'] = 4
108 d['mno'] = 5
109 d['pqr'] = 6
111 d['abc']
112 d['def']
113 d['ghi']
114 d['jkl']
115 d['mno']
116 d['pqr']
118 d['abc'] = 1
119 d['def'] = 2
120 d['ghi'] = 3
121 d['jkl'] = 4
122 d['mno'] = 5
123 d['pqr'] = 6
125 d['abc']
126 d['def']
127 d['ghi']
128 d['jkl']
129 d['mno']
130 d['pqr']
132 d['abc'] = 1
133 d['def'] = 2
134 d['ghi'] = 3
135 d['jkl'] = 4
136 d['mno'] = 5
137 d['pqr'] = 6
139 d['abc']
140 d['def']
141 d['ghi']
142 d['jkl']
143 d['mno']
144 d['pqr']
146 d['abc'] = 1
147 d['def'] = 2
148 d['ghi'] = 3
149 d['jkl'] = 4
150 d['mno'] = 5
151 d['pqr'] = 6
153 d['abc']
154 d['def']
155 d['ghi']
156 d['jkl']
157 d['mno']
158 d['pqr']
160 def calibrate(self):
162 d = {}
164 for i in xrange(self.rounds):
165 pass
167 class DictWithFloatKeys(Test):
169 version = 2.0
170 operations = 5*(6 + 6)
171 rounds = 150000
173 def test(self):
175 d = {}
177 for i in xrange(self.rounds):
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
186 d[1.234]
187 d[2.345]
188 d[3.456]
189 d[4.567]
190 d[5.678]
191 d[6.789]
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
200 d[1.234]
201 d[2.345]
202 d[3.456]
203 d[4.567]
204 d[5.678]
205 d[6.789]
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
214 d[1.234]
215 d[2.345]
216 d[3.456]
217 d[4.567]
218 d[5.678]
219 d[6.789]
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
228 d[1.234]
229 d[2.345]
230 d[3.456]
231 d[4.567]
232 d[5.678]
233 d[6.789]
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
242 d[1.234]
243 d[2.345]
244 d[3.456]
245 d[4.567]
246 d[5.678]
247 d[6.789]
249 def calibrate(self):
251 d = {}
253 for i in xrange(self.rounds):
254 pass
256 class DictWithIntegerKeys(Test):
258 version = 2.0
259 operations = 5*(6 + 6)
260 rounds = 200000
262 def test(self):
264 d = {}
266 for i in xrange(self.rounds):
268 d[1] = 1
269 d[2] = 2
270 d[3] = 3
271 d[4] = 4
272 d[5] = 5
273 d[6] = 6
275 d[1]
276 d[2]
277 d[3]
278 d[4]
279 d[5]
280 d[6]
282 d[1] = 1
283 d[2] = 2
284 d[3] = 3
285 d[4] = 4
286 d[5] = 5
287 d[6] = 6
289 d[1]
290 d[2]
291 d[3]
292 d[4]
293 d[5]
294 d[6]
296 d[1] = 1
297 d[2] = 2
298 d[3] = 3
299 d[4] = 4
300 d[5] = 5
301 d[6] = 6
303 d[1]
304 d[2]
305 d[3]
306 d[4]
307 d[5]
308 d[6]
310 d[1] = 1
311 d[2] = 2
312 d[3] = 3
313 d[4] = 4
314 d[5] = 5
315 d[6] = 6
317 d[1]
318 d[2]
319 d[3]
320 d[4]
321 d[5]
322 d[6]
324 d[1] = 1
325 d[2] = 2
326 d[3] = 3
327 d[4] = 4
328 d[5] = 5
329 d[6] = 6
331 d[1]
332 d[2]
333 d[3]
334 d[4]
335 d[5]
336 d[6]
338 def calibrate(self):
340 d = {}
342 for i in xrange(self.rounds):
343 pass
345 class SimpleDictManipulation(Test):
347 version = 2.0
348 operations = 5*(6 + 6 + 6 + 6)
349 rounds = 100000
351 def test(self):
353 d = {}
354 has_key = d.has_key
356 for i in xrange(self.rounds):
358 d[0] = 3
359 d[1] = 4
360 d[2] = 5
361 d[3] = 3
362 d[4] = 4
363 d[5] = 5
365 x = d[0]
366 x = d[1]
367 x = d[2]
368 x = d[3]
369 x = d[4]
370 x = d[5]
372 has_key(0)
373 has_key(2)
374 has_key(4)
375 has_key(6)
376 has_key(8)
377 has_key(10)
379 del d[0]
380 del d[1]
381 del d[2]
382 del d[3]
383 del d[4]
384 del d[5]
386 d[0] = 3
387 d[1] = 4
388 d[2] = 5
389 d[3] = 3
390 d[4] = 4
391 d[5] = 5
393 x = d[0]
394 x = d[1]
395 x = d[2]
396 x = d[3]
397 x = d[4]
398 x = d[5]
400 has_key(0)
401 has_key(2)
402 has_key(4)
403 has_key(6)
404 has_key(8)
405 has_key(10)
407 del d[0]
408 del d[1]
409 del d[2]
410 del d[3]
411 del d[4]
412 del d[5]
414 d[0] = 3
415 d[1] = 4
416 d[2] = 5
417 d[3] = 3
418 d[4] = 4
419 d[5] = 5
421 x = d[0]
422 x = d[1]
423 x = d[2]
424 x = d[3]
425 x = d[4]
426 x = d[5]
428 has_key(0)
429 has_key(2)
430 has_key(4)
431 has_key(6)
432 has_key(8)
433 has_key(10)
435 del d[0]
436 del d[1]
437 del d[2]
438 del d[3]
439 del d[4]
440 del d[5]
442 d[0] = 3
443 d[1] = 4
444 d[2] = 5
445 d[3] = 3
446 d[4] = 4
447 d[5] = 5
449 x = d[0]
450 x = d[1]
451 x = d[2]
452 x = d[3]
453 x = d[4]
454 x = d[5]
456 has_key(0)
457 has_key(2)
458 has_key(4)
459 has_key(6)
460 has_key(8)
461 has_key(10)
463 del d[0]
464 del d[1]
465 del d[2]
466 del d[3]
467 del d[4]
468 del d[5]
470 d[0] = 3
471 d[1] = 4
472 d[2] = 5
473 d[3] = 3
474 d[4] = 4
475 d[5] = 5
477 x = d[0]
478 x = d[1]
479 x = d[2]
480 x = d[3]
481 x = d[4]
482 x = d[5]
484 has_key(0)
485 has_key(2)
486 has_key(4)
487 has_key(6)
488 has_key(8)
489 has_key(10)
491 del d[0]
492 del d[1]
493 del d[2]
494 del d[3]
495 del d[4]
496 del d[5]
498 def calibrate(self):
500 d = {}
501 has_key = d.has_key
503 for i in xrange(self.rounds):
504 pass