1from pybench import Test 2 3class IfThenElse(Test): 4 5 version = 2.0 6 operations = 30*3 # hard to say... 7 rounds = 150000 8 9 def test(self): 10 11 a,b,c = 1,2,3 12 for i in xrange(self.rounds): 13 14 if a == 1: 15 if b == 2: 16 if c != 3: 17 c = 3 18 b = 3 19 else: 20 c = 2 21 elif b == 3: 22 b = 2 23 a = 2 24 elif a == 2: 25 a = 3 26 else: 27 a = 1 28 29 if a == 1: 30 if b == 2: 31 if c != 3: 32 c = 3 33 b = 3 34 else: 35 c = 2 36 elif b == 3: 37 b = 2 38 a = 2 39 elif a == 2: 40 a = 3 41 else: 42 a = 1 43 44 if a == 1: 45 if b == 2: 46 if c != 3: 47 c = 3 48 b = 3 49 else: 50 c = 2 51 elif b == 3: 52 b = 2 53 a = 2 54 elif a == 2: 55 a = 3 56 else: 57 a = 1 58 59 if a == 1: 60 if b == 2: 61 if c != 3: 62 c = 3 63 b = 3 64 else: 65 c = 2 66 elif b == 3: 67 b = 2 68 a = 2 69 elif a == 2: 70 a = 3 71 else: 72 a = 1 73 74 if a == 1: 75 if b == 2: 76 if c != 3: 77 c = 3 78 b = 3 79 else: 80 c = 2 81 elif b == 3: 82 b = 2 83 a = 2 84 elif a == 2: 85 a = 3 86 else: 87 a = 1 88 89 if a == 1: 90 if b == 2: 91 if c != 3: 92 c = 3 93 b = 3 94 else: 95 c = 2 96 elif b == 3: 97 b = 2 98 a = 2 99 elif a == 2: 100 a = 3 101 else: 102 a = 1 103 104 if a == 1: 105 if b == 2: 106 if c != 3: 107 c = 3 108 b = 3 109 else: 110 c = 2 111 elif b == 3: 112 b = 2 113 a = 2 114 elif a == 2: 115 a = 3 116 else: 117 a = 1 118 119 if a == 1: 120 if b == 2: 121 if c != 3: 122 c = 3 123 b = 3 124 else: 125 c = 2 126 elif b == 3: 127 b = 2 128 a = 2 129 elif a == 2: 130 a = 3 131 else: 132 a = 1 133 134 if a == 1: 135 if b == 2: 136 if c != 3: 137 c = 3 138 b = 3 139 else: 140 c = 2 141 elif b == 3: 142 b = 2 143 a = 2 144 elif a == 2: 145 a = 3 146 else: 147 a = 1 148 149 if a == 1: 150 if b == 2: 151 if c != 3: 152 c = 3 153 b = 3 154 else: 155 c = 2 156 elif b == 3: 157 b = 2 158 a = 2 159 elif a == 2: 160 a = 3 161 else: 162 a = 1 163 164 if a == 1: 165 if b == 2: 166 if c != 3: 167 c = 3 168 b = 3 169 else: 170 c = 2 171 elif b == 3: 172 b = 2 173 a = 2 174 elif a == 2: 175 a = 3 176 else: 177 a = 1 178 179 if a == 1: 180 if b == 2: 181 if c != 3: 182 c = 3 183 b = 3 184 else: 185 c = 2 186 elif b == 3: 187 b = 2 188 a = 2 189 elif a == 2: 190 a = 3 191 else: 192 a = 1 193 194 if a == 1: 195 if b == 2: 196 if c != 3: 197 c = 3 198 b = 3 199 else: 200 c = 2 201 elif b == 3: 202 b = 2 203 a = 2 204 elif a == 2: 205 a = 3 206 else: 207 a = 1 208 209 if a == 1: 210 if b == 2: 211 if c != 3: 212 c = 3 213 b = 3 214 else: 215 c = 2 216 elif b == 3: 217 b = 2 218 a = 2 219 elif a == 2: 220 a = 3 221 else: 222 a = 1 223 224 if a == 1: 225 if b == 2: 226 if c != 3: 227 c = 3 228 b = 3 229 else: 230 c = 2 231 elif b == 3: 232 b = 2 233 a = 2 234 elif a == 2: 235 a = 3 236 else: 237 a = 1 238 239 if a == 1: 240 if b == 2: 241 if c != 3: 242 c = 3 243 b = 3 244 else: 245 c = 2 246 elif b == 3: 247 b = 2 248 a = 2 249 elif a == 2: 250 a = 3 251 else: 252 a = 1 253 254 if a == 1: 255 if b == 2: 256 if c != 3: 257 c = 3 258 b = 3 259 else: 260 c = 2 261 elif b == 3: 262 b = 2 263 a = 2 264 elif a == 2: 265 a = 3 266 else: 267 a = 1 268 269 if a == 1: 270 if b == 2: 271 if c != 3: 272 c = 3 273 b = 3 274 else: 275 c = 2 276 elif b == 3: 277 b = 2 278 a = 2 279 elif a == 2: 280 a = 3 281 else: 282 a = 1 283 284 if a == 1: 285 if b == 2: 286 if c != 3: 287 c = 3 288 b = 3 289 else: 290 c = 2 291 elif b == 3: 292 b = 2 293 a = 2 294 elif a == 2: 295 a = 3 296 else: 297 a = 1 298 299 if a == 1: 300 if b == 2: 301 if c != 3: 302 c = 3 303 b = 3 304 else: 305 c = 2 306 elif b == 3: 307 b = 2 308 a = 2 309 elif a == 2: 310 a = 3 311 else: 312 a = 1 313 314 if a == 1: 315 if b == 2: 316 if c != 3: 317 c = 3 318 b = 3 319 else: 320 c = 2 321 elif b == 3: 322 b = 2 323 a = 2 324 elif a == 2: 325 a = 3 326 else: 327 a = 1 328 329 if a == 1: 330 if b == 2: 331 if c != 3: 332 c = 3 333 b = 3 334 else: 335 c = 2 336 elif b == 3: 337 b = 2 338 a = 2 339 elif a == 2: 340 a = 3 341 else: 342 a = 1 343 344 if a == 1: 345 if b == 2: 346 if c != 3: 347 c = 3 348 b = 3 349 else: 350 c = 2 351 elif b == 3: 352 b = 2 353 a = 2 354 elif a == 2: 355 a = 3 356 else: 357 a = 1 358 359 if a == 1: 360 if b == 2: 361 if c != 3: 362 c = 3 363 b = 3 364 else: 365 c = 2 366 elif b == 3: 367 b = 2 368 a = 2 369 elif a == 2: 370 a = 3 371 else: 372 a = 1 373 374 if a == 1: 375 if b == 2: 376 if c != 3: 377 c = 3 378 b = 3 379 else: 380 c = 2 381 elif b == 3: 382 b = 2 383 a = 2 384 elif a == 2: 385 a = 3 386 else: 387 a = 1 388 389 if a == 1: 390 if b == 2: 391 if c != 3: 392 c = 3 393 b = 3 394 else: 395 c = 2 396 elif b == 3: 397 b = 2 398 a = 2 399 elif a == 2: 400 a = 3 401 else: 402 a = 1 403 404 if a == 1: 405 if b == 2: 406 if c != 3: 407 c = 3 408 b = 3 409 else: 410 c = 2 411 elif b == 3: 412 b = 2 413 a = 2 414 elif a == 2: 415 a = 3 416 else: 417 a = 1 418 419 if a == 1: 420 if b == 2: 421 if c != 3: 422 c = 3 423 b = 3 424 else: 425 c = 2 426 elif b == 3: 427 b = 2 428 a = 2 429 elif a == 2: 430 a = 3 431 else: 432 a = 1 433 434 if a == 1: 435 if b == 2: 436 if c != 3: 437 c = 3 438 b = 3 439 else: 440 c = 2 441 elif b == 3: 442 b = 2 443 a = 2 444 elif a == 2: 445 a = 3 446 else: 447 a = 1 448 449 if a == 1: 450 if b == 2: 451 if c != 3: 452 c = 3 453 b = 3 454 else: 455 c = 2 456 elif b == 3: 457 b = 2 458 a = 2 459 elif a == 2: 460 a = 3 461 else: 462 a = 1 463 464 def calibrate(self): 465 466 a,b,c = 1,2,3 467 for i in xrange(self.rounds): 468 pass 469 470class NestedForLoops(Test): 471 472 version = 2.0 473 operations = 1000*10*5 474 rounds = 300 475 476 def test(self): 477 478 l1 = range(1000) 479 l2 = range(10) 480 l3 = range(5) 481 for i in xrange(self.rounds): 482 for i in l1: 483 for j in l2: 484 for k in l3: 485 pass 486 487 def calibrate(self): 488 489 l1 = range(1000) 490 l2 = range(10) 491 l3 = range(5) 492 for i in xrange(self.rounds): 493 pass 494 495class ForLoops(Test): 496 497 version = 2.0 498 operations = 5 * 5 499 rounds = 10000 500 501 def test(self): 502 503 l1 = range(100) 504 for i in xrange(self.rounds): 505 for i in l1: 506 pass 507 for i in l1: 508 pass 509 for i in l1: 510 pass 511 for i in l1: 512 pass 513 for i in l1: 514 pass 515 516 for i in l1: 517 pass 518 for i in l1: 519 pass 520 for i in l1: 521 pass 522 for i in l1: 523 pass 524 for i in l1: 525 pass 526 527 for i in l1: 528 pass 529 for i in l1: 530 pass 531 for i in l1: 532 pass 533 for i in l1: 534 pass 535 for i in l1: 536 pass 537 538 for i in l1: 539 pass 540 for i in l1: 541 pass 542 for i in l1: 543 pass 544 for i in l1: 545 pass 546 for i in l1: 547 pass 548 549 for i in l1: 550 pass 551 for i in l1: 552 pass 553 for i in l1: 554 pass 555 for i in l1: 556 pass 557 for i in l1: 558 pass 559 560 def calibrate(self): 561 562 l1 = range(1000) 563 for i in xrange(self.rounds): 564 pass 565