Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1 | from pybench import Test |
| 2 | |
| 3 | class SimpleListManipulation(Test): |
| 4 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 5 | version = 2.0 |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6 | operations = 5* (6 + 6 + 6) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 7 | rounds = 130000 |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 8 | |
| 9 | def test(self): |
| 10 | |
| 11 | l = [] |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 12 | append = l.append |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 13 | |
Guido van Rossum | 805365e | 2007-05-07 22:24:25 +0000 | [diff] [blame] | 14 | for i in range(self.rounds): |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 15 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 16 | append(2) |
| 17 | append(3) |
| 18 | append(4) |
| 19 | append(2) |
| 20 | append(3) |
| 21 | append(4) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 22 | |
| 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 Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 29 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 30 | 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 Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 37 | append(2) |
| 38 | append(3) |
| 39 | append(4) |
| 40 | append(2) |
| 41 | append(3) |
| 42 | append(4) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 43 | |
| 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 Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 50 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 51 | 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 Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 58 | append(2) |
| 59 | append(3) |
| 60 | append(4) |
| 61 | append(2) |
| 62 | append(3) |
| 63 | append(4) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 64 | |
| 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 Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 71 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 72 | 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 Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 79 | append(2) |
| 80 | append(3) |
| 81 | append(4) |
| 82 | append(2) |
| 83 | append(3) |
| 84 | append(4) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 85 | |
| 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 Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 92 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 93 | 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 Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 100 | append(2) |
| 101 | append(3) |
| 102 | append(4) |
| 103 | append(2) |
| 104 | append(3) |
| 105 | append(4) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 106 | |
| 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 Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 113 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 114 | 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 Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 128 | append = l.append |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 129 | |
Guido van Rossum | 805365e | 2007-05-07 22:24:25 +0000 | [diff] [blame] | 130 | for i in range(self.rounds): |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 131 | pass |
| 132 | |
| 133 | class ListSlicing(Test): |
| 134 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 135 | version = 2.0 |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 136 | operations = 25*(3+1+2+1) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 137 | rounds = 800 |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 138 | |
| 139 | def test(self): |
| 140 | |
Guido van Rossum | 486364b | 2007-06-30 05:01:58 +0000 | [diff] [blame] | 141 | n = list(range(100)) |
| 142 | r = list(range(25)) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 143 | |
Guido van Rossum | 805365e | 2007-05-07 22:24:25 +0000 | [diff] [blame] | 144 | for i in range(self.rounds): |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 145 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 146 | l = n[:] |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 147 | |
| 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 Brandl | bf82e37 | 2008-05-16 17:02:34 +0000 | [diff] [blame] | 160 | n = list(range(100)) |
| 161 | r = list(range(25)) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 162 | |
Guido van Rossum | 805365e | 2007-05-07 22:24:25 +0000 | [diff] [blame] | 163 | for i in range(self.rounds): |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 164 | for j in r: |
| 165 | pass |
| 166 | |
| 167 | class SmallLists(Test): |
| 168 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 169 | version = 2.0 |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 170 | operations = 5*(1+ 6 + 6 + 3 + 1) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 171 | rounds = 80000 |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 172 | |
| 173 | def test(self): |
| 174 | |
Guido van Rossum | 805365e | 2007-05-07 22:24:25 +0000 | [diff] [blame] | 175 | for i in range(self.rounds): |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 176 | |
| 177 | l = [] |
| 178 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 179 | append = l.append |
| 180 | append(2) |
| 181 | append(3) |
| 182 | append(4) |
| 183 | append(2) |
| 184 | append(3) |
| 185 | append(4) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 186 | |
| 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 Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 193 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 194 | l[:3] = [1,2,3] |
| 195 | m = l[:-1] |
| 196 | m = l[1:] |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 197 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 198 | l[-1:] = [4,5,6] |
| 199 | |
| 200 | l = [] |
| 201 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 202 | append = l.append |
| 203 | append(2) |
| 204 | append(3) |
| 205 | append(4) |
| 206 | append(2) |
| 207 | append(3) |
| 208 | append(4) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 209 | |
| 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 Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 216 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 217 | l[:3] = [1,2,3] |
| 218 | m = l[:-1] |
| 219 | m = l[1:] |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 220 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 221 | l[-1:] = [4,5,6] |
| 222 | |
| 223 | l = [] |
| 224 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 225 | append = l.append |
| 226 | append(2) |
| 227 | append(3) |
| 228 | append(4) |
| 229 | append(2) |
| 230 | append(3) |
| 231 | append(4) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 232 | |
| 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 Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 239 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 240 | l[:3] = [1,2,3] |
| 241 | m = l[:-1] |
| 242 | m = l[1:] |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 243 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 244 | l[-1:] = [4,5,6] |
| 245 | |
| 246 | l = [] |
| 247 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 248 | append = l.append |
| 249 | append(2) |
| 250 | append(3) |
| 251 | append(4) |
| 252 | append(2) |
| 253 | append(3) |
| 254 | append(4) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 255 | |
| 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 Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 262 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 263 | l[:3] = [1,2,3] |
| 264 | m = l[:-1] |
| 265 | m = l[1:] |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 266 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 267 | l[-1:] = [4,5,6] |
| 268 | |
| 269 | l = [] |
| 270 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 271 | append = l.append |
| 272 | append(2) |
| 273 | append(3) |
| 274 | append(4) |
| 275 | append(2) |
| 276 | append(3) |
| 277 | append(4) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 278 | |
| 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 Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 285 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 286 | l[:3] = [1,2,3] |
| 287 | m = l[:-1] |
| 288 | m = l[1:] |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 289 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 290 | l[-1:] = [4,5,6] |
| 291 | |
| 292 | def calibrate(self): |
| 293 | |
Guido van Rossum | 805365e | 2007-05-07 22:24:25 +0000 | [diff] [blame] | 294 | for i in range(self.rounds): |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 295 | pass |
Antoine Pitrou | 2a013ea | 2008-12-27 20:39:28 +0000 | [diff] [blame] | 296 | |
| 297 | class 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 | |
| 323 | class 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 |