1from pybench import Test 2 3class SimpleIntegerArithmetic(Test): 4 5 version = 2.0 6 operations = 5 * (3 + 5 + 5 + 3 + 3 + 3) 7 rounds = 120000 8 9 def test(self): 10 11 for i in xrange(self.rounds): 12 13 a = 2 14 b = 3 15 c = 3 16 17 c = a + b 18 c = b + c 19 c = c + a 20 c = a + b 21 c = b + c 22 23 c = c - a 24 c = a - b 25 c = b - c 26 c = c - a 27 c = b - c 28 29 c = a / b 30 c = b / a 31 c = c / b 32 33 c = a * b 34 c = b * a 35 c = c * b 36 37 c = a / b 38 c = b / a 39 c = c / b 40 41 a = 2 42 b = 3 43 c = 3 44 45 c = a + b 46 c = b + c 47 c = c + a 48 c = a + b 49 c = b + c 50 51 c = c - a 52 c = a - b 53 c = b - c 54 c = c - a 55 c = b - c 56 57 c = a / b 58 c = b / a 59 c = c / b 60 61 c = a * b 62 c = b * a 63 c = c * b 64 65 c = a / b 66 c = b / a 67 c = c / b 68 69 a = 2 70 b = 3 71 c = 3 72 73 c = a + b 74 c = b + c 75 c = c + a 76 c = a + b 77 c = b + c 78 79 c = c - a 80 c = a - b 81 c = b - c 82 c = c - a 83 c = b - c 84 85 c = a / b 86 c = b / a 87 c = c / b 88 89 c = a * b 90 c = b * a 91 c = c * b 92 93 c = a / b 94 c = b / a 95 c = c / b 96 97 a = 2 98 b = 3 99 c = 3 100 101 c = a + b 102 c = b + c 103 c = c + a 104 c = a + b 105 c = b + c 106 107 c = c - a 108 c = a - b 109 c = b - c 110 c = c - a 111 c = b - c 112 113 c = a / b 114 c = b / a 115 c = c / b 116 117 c = a * b 118 c = b * a 119 c = c * b 120 121 c = a / b 122 c = b / a 123 c = c / b 124 125 a = 2 126 b = 3 127 c = 3 128 129 c = a + b 130 c = b + c 131 c = c + a 132 c = a + b 133 c = b + c 134 135 c = c - a 136 c = a - b 137 c = b - c 138 c = c - a 139 c = b - c 140 141 c = a / b 142 c = b / a 143 c = c / b 144 145 c = a * b 146 c = b * a 147 c = c * b 148 149 c = a / b 150 c = b / a 151 c = c / b 152 153 def calibrate(self): 154 155 for i in xrange(self.rounds): 156 pass 157 158class SimpleFloatArithmetic(Test): 159 160 version = 2.0 161 operations = 5 * (3 + 5 + 5 + 3 + 3 + 3) 162 rounds = 120000 163 164 def test(self): 165 166 for i in xrange(self.rounds): 167 168 a = 2.1 169 b = 3.3332 170 c = 3.14159 171 172 c = a + b 173 c = b + c 174 c = c + a 175 c = a + b 176 c = b + c 177 178 c = c - a 179 c = a - b 180 c = b - c 181 c = c - a 182 c = b - c 183 184 c = a / b 185 c = b / a 186 c = c / b 187 188 c = a * b 189 c = b * a 190 c = c * b 191 192 c = a / b 193 c = b / a 194 c = c / b 195 196 a = 2.1 197 b = 3.3332 198 c = 3.14159 199 200 c = a + b 201 c = b + c 202 c = c + a 203 c = a + b 204 c = b + c 205 206 c = c - a 207 c = a - b 208 c = b - c 209 c = c - a 210 c = b - c 211 212 c = a / b 213 c = b / a 214 c = c / b 215 216 c = a * b 217 c = b * a 218 c = c * b 219 220 c = a / b 221 c = b / a 222 c = c / b 223 224 a = 2.1 225 b = 3.3332 226 c = 3.14159 227 228 c = a + b 229 c = b + c 230 c = c + a 231 c = a + b 232 c = b + c 233 234 c = c - a 235 c = a - b 236 c = b - c 237 c = c - a 238 c = b - c 239 240 c = a / b 241 c = b / a 242 c = c / b 243 244 c = a * b 245 c = b * a 246 c = c * b 247 248 c = a / b 249 c = b / a 250 c = c / b 251 252 a = 2.1 253 b = 3.3332 254 c = 3.14159 255 256 c = a + b 257 c = b + c 258 c = c + a 259 c = a + b 260 c = b + c 261 262 c = c - a 263 c = a - b 264 c = b - c 265 c = c - a 266 c = b - c 267 268 c = a / b 269 c = b / a 270 c = c / b 271 272 c = a * b 273 c = b * a 274 c = c * b 275 276 c = a / b 277 c = b / a 278 c = c / b 279 280 a = 2.1 281 b = 3.3332 282 c = 3.14159 283 284 c = a + b 285 c = b + c 286 c = c + a 287 c = a + b 288 c = b + c 289 290 c = c - a 291 c = a - b 292 c = b - c 293 c = c - a 294 c = b - c 295 296 c = a / b 297 c = b / a 298 c = c / b 299 300 c = a * b 301 c = b * a 302 c = c * b 303 304 c = a / b 305 c = b / a 306 c = c / b 307 308 def calibrate(self): 309 310 for i in xrange(self.rounds): 311 pass 312 313class SimpleIntFloatArithmetic(Test): 314 315 version = 2.0 316 operations = 5 * (3 + 5 + 5 + 3 + 3 + 3) 317 rounds = 120000 318 319 def test(self): 320 321 for i in xrange(self.rounds): 322 323 a = 2 324 b = 3 325 c = 3.14159 326 327 c = a + b 328 c = b + c 329 c = c + a 330 c = a + b 331 c = b + c 332 333 c = c - a 334 c = a - b 335 c = b - c 336 c = c - a 337 c = b - c 338 339 c = a / b 340 c = b / a 341 c = c / b 342 343 c = a * b 344 c = b * a 345 c = c * b 346 347 c = a / b 348 c = b / a 349 c = c / b 350 351 a = 2 352 b = 3 353 c = 3.14159 354 355 c = a + b 356 c = b + c 357 c = c + a 358 c = a + b 359 c = b + c 360 361 c = c - a 362 c = a - b 363 c = b - c 364 c = c - a 365 c = b - c 366 367 c = a / b 368 c = b / a 369 c = c / b 370 371 c = a * b 372 c = b * a 373 c = c * b 374 375 c = a / b 376 c = b / a 377 c = c / b 378 379 a = 2 380 b = 3 381 c = 3.14159 382 383 c = a + b 384 c = b + c 385 c = c + a 386 c = a + b 387 c = b + c 388 389 c = c - a 390 c = a - b 391 c = b - c 392 c = c - a 393 c = b - c 394 395 c = a / b 396 c = b / a 397 c = c / b 398 399 c = a * b 400 c = b * a 401 c = c * b 402 403 c = a / b 404 c = b / a 405 c = c / b 406 407 a = 2 408 b = 3 409 c = 3.14159 410 411 c = a + b 412 c = b + c 413 c = c + a 414 c = a + b 415 c = b + c 416 417 c = c - a 418 c = a - b 419 c = b - c 420 c = c - a 421 c = b - c 422 423 c = a / b 424 c = b / a 425 c = c / b 426 427 c = a * b 428 c = b * a 429 c = c * b 430 431 c = a / b 432 c = b / a 433 c = c / b 434 435 a = 2 436 b = 3 437 c = 3.14159 438 439 c = a + b 440 c = b + c 441 c = c + a 442 c = a + b 443 c = b + c 444 445 c = c - a 446 c = a - b 447 c = b - c 448 c = c - a 449 c = b - c 450 451 c = a / b 452 c = b / a 453 c = c / b 454 455 c = a * b 456 c = b * a 457 c = c * b 458 459 c = a / b 460 c = b / a 461 c = c / b 462 463 def calibrate(self): 464 465 for i in xrange(self.rounds): 466 pass 467 468 469class SimpleLongArithmetic(Test): 470 471 version = 2.0 472 operations = 5 * (3 + 5 + 5 + 3 + 3 + 3) 473 rounds = 60000 474 475 def test(self): 476 477 for i in xrange(self.rounds): 478 479 a = 2220001L 480 b = 100001L 481 c = 30005L 482 483 c = a + b 484 c = b + c 485 c = c + a 486 c = a + b 487 c = b + c 488 489 c = c - a 490 c = a - b 491 c = b - c 492 c = c - a 493 c = b - c 494 495 c = a / b 496 c = b / a 497 c = c / b 498 499 c = a * b 500 c = b * a 501 c = c * b 502 503 c = a / b 504 c = b / a 505 c = c / b 506 507 a = 2220001L 508 b = 100001L 509 c = 30005L 510 511 c = a + b 512 c = b + c 513 c = c + a 514 c = a + b 515 c = b + c 516 517 c = c - a 518 c = a - b 519 c = b - c 520 c = c - a 521 c = b - c 522 523 c = a / b 524 c = b / a 525 c = c / b 526 527 c = a * b 528 c = b * a 529 c = c * b 530 531 c = a / b 532 c = b / a 533 c = c / b 534 535 a = 2220001L 536 b = 100001L 537 c = 30005L 538 539 c = a + b 540 c = b + c 541 c = c + a 542 c = a + b 543 c = b + c 544 545 c = c - a 546 c = a - b 547 c = b - c 548 c = c - a 549 c = b - c 550 551 c = a / b 552 c = b / a 553 c = c / b 554 555 c = a * b 556 c = b * a 557 c = c * b 558 559 c = a / b 560 c = b / a 561 c = c / b 562 563 a = 2220001L 564 b = 100001L 565 c = 30005L 566 567 c = a + b 568 c = b + c 569 c = c + a 570 c = a + b 571 c = b + c 572 573 c = c - a 574 c = a - b 575 c = b - c 576 c = c - a 577 c = b - c 578 579 c = a / b 580 c = b / a 581 c = c / b 582 583 c = a * b 584 c = b * a 585 c = c * b 586 587 c = a / b 588 c = b / a 589 c = c / b 590 591 a = 2220001L 592 b = 100001L 593 c = 30005L 594 595 c = a + b 596 c = b + c 597 c = c + a 598 c = a + b 599 c = b + c 600 601 c = c - a 602 c = a - b 603 c = b - c 604 c = c - a 605 c = b - c 606 607 c = a / b 608 c = b / a 609 c = c / b 610 611 c = a * b 612 c = b * a 613 c = c * b 614 615 c = a / b 616 c = b / a 617 c = c / b 618 619 def calibrate(self): 620 621 for i in xrange(self.rounds): 622 pass 623 624class SimpleComplexArithmetic(Test): 625 626 version = 2.0 627 operations = 5 * (3 + 5 + 5 + 3 + 3 + 3) 628 rounds = 80000 629 630 def test(self): 631 632 for i in xrange(self.rounds): 633 634 a = 2 + 3j 635 b = 2.5 + 4.5j 636 c = 1.2 + 6.2j 637 638 c = a + b 639 c = b + c 640 c = c + a 641 c = a + b 642 c = b + c 643 644 c = c - a 645 c = a - b 646 c = b - c 647 c = c - a 648 c = b - c 649 650 c = a / b 651 c = b / a 652 c = c / b 653 654 c = a * b 655 c = b * a 656 c = c * b 657 658 c = a / b 659 c = b / a 660 c = c / b 661 662 a = 2 + 3j 663 b = 2.5 + 4.5j 664 c = 1.2 + 6.2j 665 666 c = a + b 667 c = b + c 668 c = c + a 669 c = a + b 670 c = b + c 671 672 c = c - a 673 c = a - b 674 c = b - c 675 c = c - a 676 c = b - c 677 678 c = a / b 679 c = b / a 680 c = c / b 681 682 c = a * b 683 c = b * a 684 c = c * b 685 686 c = a / b 687 c = b / a 688 c = c / b 689 690 a = 2 + 3j 691 b = 2.5 + 4.5j 692 c = 1.2 + 6.2j 693 694 c = a + b 695 c = b + c 696 c = c + a 697 c = a + b 698 c = b + c 699 700 c = c - a 701 c = a - b 702 c = b - c 703 c = c - a 704 c = b - c 705 706 c = a / b 707 c = b / a 708 c = c / b 709 710 c = a * b 711 c = b * a 712 c = c * b 713 714 c = a / b 715 c = b / a 716 c = c / b 717 718 a = 2 + 3j 719 b = 2.5 + 4.5j 720 c = 1.2 + 6.2j 721 722 c = a + b 723 c = b + c 724 c = c + a 725 c = a + b 726 c = b + c 727 728 c = c - a 729 c = a - b 730 c = b - c 731 c = c - a 732 c = b - c 733 734 c = a / b 735 c = b / a 736 c = c / b 737 738 c = a * b 739 c = b * a 740 c = c * b 741 742 c = a / b 743 c = b / a 744 c = c / b 745 746 a = 2 + 3j 747 b = 2.5 + 4.5j 748 c = 1.2 + 6.2j 749 750 c = a + b 751 c = b + c 752 c = c + a 753 c = a + b 754 c = b + c 755 756 c = c - a 757 c = a - b 758 c = b - c 759 c = c - a 760 c = b - c 761 762 c = a / b 763 c = b / a 764 c = c / b 765 766 c = a * b 767 c = b * a 768 c = c * b 769 770 c = a / b 771 c = b / a 772 c = c / b 773 774 def calibrate(self): 775 776 for i in xrange(self.rounds): 777 pass 778