blob: 29dabeff5b239a0e7f2541ea6f5600fbd0f186ac [file] [log] [blame]
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001from pybench import Test
2
3class SimpleListManipulation(Test):
4
Thomas Wouters0e3f5912006-08-11 14:57:12 +00005 version = 2.0
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00006 operations = 5* (6 + 6 + 6)
Thomas Wouters0e3f5912006-08-11 14:57:12 +00007 rounds = 130000
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00008
9 def test(self):
10
11 l = []
Thomas Wouters0e3f5912006-08-11 14:57:12 +000012 append = l.append
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000013
Guido van Rossum805365e2007-05-07 22:24:25 +000014 for i in range(self.rounds):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000015
Thomas Wouters0e3f5912006-08-11 14:57:12 +000016 append(2)
17 append(3)
18 append(4)
19 append(2)
20 append(3)
21 append(4)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000022
23 l[0] = 3
24 l[1] = 4
25 l[2] = 5
26 l[3] = 3
27 l[4] = 4
28 l[5] = 5
Thomas Wouters477c8d52006-05-27 19:21:47 +000029
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000030 x = l[0]
31 x = l[1]
32 x = l[2]
33 x = l[3]
34 x = l[4]
35 x = l[5]
36
Thomas Wouters0e3f5912006-08-11 14:57:12 +000037 append(2)
38 append(3)
39 append(4)
40 append(2)
41 append(3)
42 append(4)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000043
44 l[0] = 3
45 l[1] = 4
46 l[2] = 5
47 l[3] = 3
48 l[4] = 4
49 l[5] = 5
Thomas Wouters477c8d52006-05-27 19:21:47 +000050
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000051 x = l[0]
52 x = l[1]
53 x = l[2]
54 x = l[3]
55 x = l[4]
56 x = l[5]
57
Thomas Wouters0e3f5912006-08-11 14:57:12 +000058 append(2)
59 append(3)
60 append(4)
61 append(2)
62 append(3)
63 append(4)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000064
65 l[0] = 3
66 l[1] = 4
67 l[2] = 5
68 l[3] = 3
69 l[4] = 4
70 l[5] = 5
Thomas Wouters477c8d52006-05-27 19:21:47 +000071
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000072 x = l[0]
73 x = l[1]
74 x = l[2]
75 x = l[3]
76 x = l[4]
77 x = l[5]
78
Thomas Wouters0e3f5912006-08-11 14:57:12 +000079 append(2)
80 append(3)
81 append(4)
82 append(2)
83 append(3)
84 append(4)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000085
86 l[0] = 3
87 l[1] = 4
88 l[2] = 5
89 l[3] = 3
90 l[4] = 4
91 l[5] = 5
Thomas Wouters477c8d52006-05-27 19:21:47 +000092
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000093 x = l[0]
94 x = l[1]
95 x = l[2]
96 x = l[3]
97 x = l[4]
98 x = l[5]
99
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000100 append(2)
101 append(3)
102 append(4)
103 append(2)
104 append(3)
105 append(4)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000106
107 l[0] = 3
108 l[1] = 4
109 l[2] = 5
110 l[3] = 3
111 l[4] = 4
112 l[5] = 5
Thomas Wouters477c8d52006-05-27 19:21:47 +0000113
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000114 x = l[0]
115 x = l[1]
116 x = l[2]
117 x = l[3]
118 x = l[4]
119 x = l[5]
120
121 if len(l) > 10000:
122 # cut down the size
123 del l[:]
124
125 def calibrate(self):
126
127 l = []
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000128 append = l.append
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000129
Guido van Rossum805365e2007-05-07 22:24:25 +0000130 for i in range(self.rounds):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000131 pass
132
133class ListSlicing(Test):
134
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000135 version = 2.0
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000136 operations = 25*(3+1+2+1)
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000137 rounds = 800
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000138
139 def test(self):
140
Guido van Rossum486364b2007-06-30 05:01:58 +0000141 n = list(range(100))
142 r = list(range(25))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000143
Guido van Rossum805365e2007-05-07 22:24:25 +0000144 for i in range(self.rounds):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000145
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000146 l = n[:]
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000147
148 for j in r:
149
150 m = l[50:]
151 m = l[:25]
152 m = l[50:55]
153 l[:3] = n
154 m = l[:-1]
155 m = l[1:]
156 l[-1:] = n
157
158 def calibrate(self):
159
Georg Brandlbf82e372008-05-16 17:02:34 +0000160 n = list(range(100))
161 r = list(range(25))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000162
Guido van Rossum805365e2007-05-07 22:24:25 +0000163 for i in range(self.rounds):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000164 for j in r:
165 pass
166
167class SmallLists(Test):
168
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000169 version = 2.0
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000170 operations = 5*(1+ 6 + 6 + 3 + 1)
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000171 rounds = 80000
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000172
173 def test(self):
174
Guido van Rossum805365e2007-05-07 22:24:25 +0000175 for i in range(self.rounds):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000176
177 l = []
178
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000179 append = l.append
180 append(2)
181 append(3)
182 append(4)
183 append(2)
184 append(3)
185 append(4)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000186
187 l[0] = 3
188 l[1] = 4
189 l[2] = 5
190 l[3] = 3
191 l[4] = 4
192 l[5] = 5
Thomas Wouters477c8d52006-05-27 19:21:47 +0000193
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000194 l[:3] = [1,2,3]
195 m = l[:-1]
196 m = l[1:]
Thomas Wouters477c8d52006-05-27 19:21:47 +0000197
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000198 l[-1:] = [4,5,6]
199
200 l = []
201
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000202 append = l.append
203 append(2)
204 append(3)
205 append(4)
206 append(2)
207 append(3)
208 append(4)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000209
210 l[0] = 3
211 l[1] = 4
212 l[2] = 5
213 l[3] = 3
214 l[4] = 4
215 l[5] = 5
Thomas Wouters477c8d52006-05-27 19:21:47 +0000216
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000217 l[:3] = [1,2,3]
218 m = l[:-1]
219 m = l[1:]
Thomas Wouters477c8d52006-05-27 19:21:47 +0000220
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000221 l[-1:] = [4,5,6]
222
223 l = []
224
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000225 append = l.append
226 append(2)
227 append(3)
228 append(4)
229 append(2)
230 append(3)
231 append(4)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000232
233 l[0] = 3
234 l[1] = 4
235 l[2] = 5
236 l[3] = 3
237 l[4] = 4
238 l[5] = 5
Thomas Wouters477c8d52006-05-27 19:21:47 +0000239
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000240 l[:3] = [1,2,3]
241 m = l[:-1]
242 m = l[1:]
Thomas Wouters477c8d52006-05-27 19:21:47 +0000243
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000244 l[-1:] = [4,5,6]
245
246 l = []
247
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000248 append = l.append
249 append(2)
250 append(3)
251 append(4)
252 append(2)
253 append(3)
254 append(4)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000255
256 l[0] = 3
257 l[1] = 4
258 l[2] = 5
259 l[3] = 3
260 l[4] = 4
261 l[5] = 5
Thomas Wouters477c8d52006-05-27 19:21:47 +0000262
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000263 l[:3] = [1,2,3]
264 m = l[:-1]
265 m = l[1:]
Thomas Wouters477c8d52006-05-27 19:21:47 +0000266
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000267 l[-1:] = [4,5,6]
268
269 l = []
270
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000271 append = l.append
272 append(2)
273 append(3)
274 append(4)
275 append(2)
276 append(3)
277 append(4)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000278
279 l[0] = 3
280 l[1] = 4
281 l[2] = 5
282 l[3] = 3
283 l[4] = 4
284 l[5] = 5
Thomas Wouters477c8d52006-05-27 19:21:47 +0000285
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000286 l[:3] = [1,2,3]
287 m = l[:-1]
288 m = l[1:]
Thomas Wouters477c8d52006-05-27 19:21:47 +0000289
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000290 l[-1:] = [4,5,6]
291
292 def calibrate(self):
293
Guido van Rossum805365e2007-05-07 22:24:25 +0000294 for i in range(self.rounds):
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000295 pass
Antoine Pitrou2a013ea2008-12-27 20:39:28 +0000296
297class SimpleListComprehensions(Test):
298
299 version = 2.0
300 operations = 6
301 rounds = 20000
302
303 def test(self):
304
305 n = list(range(10)) * 10
306
307 for i in range(self.rounds):
308 l = [x for x in n]
309 l = [x for x in n if x]
310 l = [x for x in n if not x]
311
312 l = [x for x in n]
313 l = [x for x in n if x]
314 l = [x for x in n if not x]
315
316 def calibrate(self):
317
318 n = list(range(10)) * 10
319
320 for i in range(self.rounds):
321 pass
322
323class NestedListComprehensions(Test):
324
325 version = 2.0
326 operations = 6
327 rounds = 20000
328
329 def test(self):
330
331 m = list(range(10))
332 n = list(range(10))
333
334 for i in range(self.rounds):
335 l = [x for x in n for y in m]
336 l = [y for x in n for y in m]
337
338 l = [x for x in n for y in m if y]
339 l = [y for x in n for y in m if x]
340
341 l = [x for x in n for y in m if not y]
342 l = [y for x in n for y in m if not x]
343
344 def calibrate(self):
345
346 m = list(range(10))
347 n = list(range(10))
348
349 for i in range(self.rounds):
350 pass