github.com/klaytn/klaytn@v1.12.1/contracts/computationcost/opcodeBench.sol (about) 1 // Copyright 2018 The klaytn Authors 2 // 3 // This file is part of the klaytn library. 4 // 5 // The klaytn library is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Lesser General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // The klaytn library is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Lesser General Public License for more details. 14 // 15 // You should have received a copy of the GNU Lesser General Public License 16 // along with the klaytn library. If not, see <http://www.gnu.org/licenses/>. 17 18 pragma solidity ^0.4.24; 19 20 contract StopContract { 21 function Sstop() view { 22 assembly { 23 stop 24 } 25 } 26 27 function ReturnData(uint size) returns (bytes) { 28 return new bytes(size); 29 } 30 } 31 32 contract OpCodeBenchmarkContract { 33 34 mapping(uint => uint) public testMap; 35 36 function Add(uint loopCount, uint x, uint y) returns (uint) { 37 uint i; 38 uint k; 39 for (i = 0; i < loopCount; i++) { 40 assembly { 41 k := add(x,y) 42 } 43 } 44 return k; 45 } 46 47 function Sub(uint loopCount, uint x, uint y) returns (uint) { 48 uint i; 49 uint k; 50 for (i = 0; i < loopCount; i++) { 51 assembly { 52 k := sub(x,y) 53 } 54 } 55 return k; 56 } 57 58 function Mul(uint loopCount, uint x, uint y) returns (uint) { 59 uint i; 60 uint k; 61 for (i = 0; i < loopCount; i++) { 62 assembly { 63 k := mul(x,y) 64 } 65 } 66 return k; 67 } 68 69 function Div(uint loopCount, uint x, uint y) returns (uint) { 70 uint i; 71 uint k = loopCount; 72 for (i = 1; i < loopCount; i++) { 73 assembly { 74 k := div(x,y) 75 } 76 } 77 return k; 78 } 79 80 function Sdiv(uint loopCount, uint x, uint y) returns (uint) { 81 uint i; 82 uint k = loopCount; 83 for (i = 1; i < loopCount; i++) { 84 assembly { 85 k := sdiv(x,y) 86 } 87 } 88 return k; 89 } 90 91 function Mod(uint loopCount, uint x, uint y) returns (uint) { 92 uint i; 93 uint k = loopCount; 94 for (i = 1; i < loopCount; i++) { 95 assembly { 96 k := mod(x,y) 97 } 98 } 99 return k; 100 } 101 102 function Smod(uint loopCount, uint x, uint y) returns (uint) { 103 uint i; 104 uint k = loopCount; 105 for (i = 1; i < loopCount; i++) { 106 assembly { 107 k := smod(x,y) 108 } 109 } 110 return k; 111 } 112 113 function Exp(uint loopCount, uint base, uint e) returns (uint) { 114 uint i; 115 uint k = loopCount; 116 for (i = 1; i < loopCount; i++) { 117 assembly { 118 k := exp(base, e) 119 } 120 } 121 return k; 122 } 123 124 function Not(uint loopCount) returns (uint) { 125 uint i; 126 uint k = loopCount; 127 for (i = 1; i < loopCount; i++) { 128 assembly { 129 k := not(i) 130 } 131 } 132 return k; 133 } 134 135 function Lt(uint loopCount) returns (uint) { 136 uint i; 137 uint k = loopCount; 138 for (i = 1; i < loopCount; i++) { 139 assembly { 140 k := lt(k, i) 141 } 142 } 143 return k; 144 } 145 146 function Gt(uint loopCount) returns (uint) { 147 uint i; 148 uint k = loopCount; 149 for (i = 1; i < loopCount; i++) { 150 assembly { 151 k := gt(k, i) 152 } 153 } 154 return k; 155 } 156 157 function Slt(uint loopCount) returns (uint) { 158 uint i; 159 uint k = loopCount; 160 for (i = 1; i < loopCount; i++) { 161 assembly { 162 k := slt(k, i) 163 } 164 } 165 return k; 166 } 167 168 function Sgt(uint loopCount) returns (uint) { 169 uint i; 170 uint k = loopCount; 171 for (i = 1; i < loopCount; i++) { 172 assembly { 173 k := sgt(k, i) 174 } 175 } 176 return k; 177 } 178 179 function Eq(uint loopCount) returns (uint) { 180 uint i; 181 uint k = loopCount; 182 for (i = 1; i < loopCount; i++) { 183 assembly { 184 k := eq(k, i) 185 } 186 } 187 return k; 188 } 189 190 function Iszero(uint loopCount) returns (uint) { 191 uint i; 192 uint k = loopCount; 193 for (i = 1; i < loopCount; i++) { 194 assembly { 195 k := iszero(i) 196 } 197 } 198 return k; 199 } 200 201 function And(uint loopCount) returns (uint) { 202 uint i; 203 uint k = loopCount; 204 for (i = 1; i < loopCount; i++) { 205 assembly { 206 k := and(k, i) 207 } 208 } 209 return k; 210 } 211 212 function Or(uint loopCount) returns (uint) { 213 uint i; 214 uint k = loopCount; 215 for (i = 1; i < loopCount; i++) { 216 assembly { 217 k := or(k, i) 218 } 219 } 220 return k; 221 } 222 223 function Xor(uint loopCount) returns (uint) { 224 uint i; 225 uint k = loopCount; 226 for (i = 1; i < loopCount; i++) { 227 assembly { 228 k := xor(k, i) 229 } 230 } 231 return k; 232 } 233 234 function Byte(uint loopCount) returns (uint) { 235 uint i; 236 uint k = loopCount; 237 for (i = 1; i < loopCount; i++) { 238 assembly { 239 k := byte(1, i) 240 } 241 } 242 return k; 243 } 244 245 function Shl(uint loopCount, uint x, uint y) returns (uint) { 246 uint i; 247 uint k = loopCount; 248 for (i = 1; i < loopCount; i++) { 249 assembly { 250 k := shl(x, y) 251 } 252 } 253 return k; 254 } 255 256 function Shr(uint loopCount, uint x, uint y) returns (uint) { 257 uint i; 258 uint k = loopCount; 259 for (i = 1; i < loopCount; i++) { 260 assembly { 261 k := shr(x, y) 262 } 263 } 264 return k; 265 } 266 267 function Sar(uint loopCount, uint x, uint y) returns (uint) { 268 uint i; 269 uint k = loopCount; 270 for (i = 1; i < loopCount; i++) { 271 assembly { 272 k := sar(x, y) 273 } 274 } 275 return k; 276 } 277 278 function Addmod(uint loopCount, uint x, uint y, uint m) returns (uint) { 279 uint i; 280 uint k = loopCount; 281 for (i = 1; i < loopCount; i++) { 282 assembly { 283 k := addmod(x, y, m) 284 } 285 } 286 return k; 287 } 288 289 function Mulmod(uint loopCount, uint x, uint y, uint m) returns (uint) { 290 uint i; 291 uint k = loopCount; 292 for (i = 1; i < loopCount; i++) { 293 assembly { 294 k := mulmod(x, y, m) 295 } 296 } 297 return k; 298 } 299 300 function SignExtend(uint loopCount, uint x, uint y) returns (uint) { 301 uint i; 302 uint k = loopCount; 303 for (i = 1; i < loopCount; i++) { 304 assembly { 305 k := signextend(x, y) 306 } 307 } 308 return k; 309 } 310 311 function Sha3(uint loopCount) returns (uint) { 312 uint i; 313 uint k = loopCount; 314 for (i = 1; i < loopCount; i++) { 315 assembly { 316 k := sha3(i, k) 317 } 318 } 319 return k; 320 } 321 322 function Pc(uint loopCount) returns (uint) { 323 uint i; 324 uint k = loopCount; 325 for (i = 1; i < loopCount; i++) { 326 assembly { 327 k := pc() 328 } 329 } 330 return k; 331 } 332 333 function Dup1(uint loopCount) returns (uint) { 334 uint i; 335 uint k = loopCount; 336 for (i = 1; i < loopCount; i++) { 337 assembly { 338 dup1 339 pop 340 } 341 } 342 return k; 343 } 344 345 function Dup2(uint loopCount) returns (uint) { 346 uint i; 347 uint k = loopCount; 348 for (i = 1; i < loopCount; i++) { 349 assembly { 350 dup2 351 pop 352 } 353 } 354 return k; 355 } 356 357 function Dup3(uint loopCount) returns (uint) { 358 uint i; 359 uint k = loopCount; 360 for (i = 1; i < loopCount; i++) { 361 assembly { 362 dup3 363 pop 364 } 365 } 366 return k; 367 } 368 369 function Dup4(uint loopCount) returns (uint) { 370 uint i; 371 uint k = loopCount; 372 for (i = 1; i < loopCount; i++) { 373 assembly { 374 dup4 pop 375 } 376 } 377 return k; 378 } 379 380 function Dup5(uint loopCount) returns (uint) { 381 uint i; 382 uint k = loopCount; 383 for (i = 1; i < loopCount; i++) { 384 assembly { 385 dup5 pop 386 } 387 } 388 return k; 389 } 390 391 function Dup6(uint loopCount) returns (uint) { 392 uint i; 393 uint k = loopCount; 394 for (i = 1; i < loopCount; i++) { 395 assembly { 396 dup6 pop 397 } 398 } 399 return k; 400 } 401 402 function Dup7(uint loopCount) returns (uint) { 403 uint i; 404 uint k = loopCount; 405 for (i = 1; i < loopCount; i++) { 406 assembly { 407 dup7 pop 408 } 409 } 410 return k; 411 } 412 413 function Dup8(uint loopCount) returns (uint) { 414 uint i; 415 uint k = loopCount; 416 for (i = 1; i < loopCount; i++) { 417 assembly { 418 dup8 pop 419 } 420 } 421 return k; 422 } 423 424 function Dup9(uint loopCount) returns (uint) { 425 uint i; 426 uint k = loopCount; 427 for (i = 1; i < loopCount; i++) { 428 assembly { 429 dup9 pop 430 } 431 } 432 return k; 433 } 434 435 function Dup10(uint loopCount) returns (uint) { 436 uint i; 437 uint k = loopCount; 438 for (i = 1; i < loopCount; i++) { 439 assembly { 440 dup10 pop 441 } 442 } 443 return k; 444 } 445 446 function Dup11(uint loopCount) returns (uint) { 447 uint i; 448 uint k = loopCount; 449 for (i = 1; i < loopCount; i++) { 450 assembly { 451 dup11 pop 452 } 453 } 454 return k; 455 } 456 457 function Dup12(uint loopCount) returns (uint) { 458 uint i; 459 uint k = loopCount; 460 for (i = 1; i < loopCount; i++) { 461 assembly { 462 dup12 pop 463 } 464 } 465 return k; 466 } 467 468 function Dup13(uint loopCount) returns (uint) { 469 uint i; 470 uint k = loopCount; 471 for (i = 1; i < loopCount; i++) { 472 assembly { 473 dup13 pop 474 } 475 } 476 return k; 477 } 478 479 function Dup14(uint loopCount) returns (uint) { 480 uint i; 481 uint k = loopCount; 482 for (i = 1; i < loopCount; i++) { 483 assembly { 484 dup14 pop 485 } 486 } 487 return k; 488 } 489 490 function Dup15(uint loopCount) returns (uint) { 491 uint i; 492 uint k = loopCount; 493 for (i = 1; i < loopCount; i++) { 494 assembly { 495 dup15 pop 496 } 497 } 498 return k; 499 } 500 501 function Dup16(uint loopCount) returns (uint) { 502 uint i; 503 uint k = loopCount; 504 for (i = 1; i < loopCount; i++) { 505 assembly { 506 dup16 pop 507 } 508 } 509 return k; 510 } 511 512 function Swap1(uint loopCount) returns (uint) { 513 uint i; 514 uint k = loopCount; 515 for (i = 1; i < loopCount; i++) { 516 assembly { 517 swap1 518 swap1 519 } 520 } 521 return k; 522 } 523 524 function Swap2(uint loopCount) returns (uint) { 525 uint i; 526 uint k = loopCount; 527 for (i = 1; i < loopCount; i++) { 528 assembly { 529 swap2 530 swap2 531 } 532 } 533 return k; 534 } 535 536 function Swap3(uint loopCount) returns (uint) { 537 uint i; 538 uint k = loopCount; 539 for (i = 1; i < loopCount; i++) { 540 assembly { 541 swap3 swap3 542 } 543 } 544 return k; 545 } 546 547 function Swap4(uint loopCount) returns (uint) { 548 uint i; 549 uint k = loopCount; 550 for (i = 1; i < loopCount; i++) { 551 assembly { 552 swap4 swap4 553 } 554 } 555 return k; 556 } 557 558 function Swap5(uint loopCount) returns (uint) { 559 uint i; 560 uint k = loopCount; 561 for (i = 1; i < loopCount; i++) { 562 assembly { swap5 swap5 } 563 } 564 return k; 565 } 566 567 function Swap6(uint loopCount) returns (uint) { 568 uint i; 569 uint k = loopCount; 570 for (i = 1; i < loopCount; i++) { 571 assembly { swap6 swap6 } 572 } 573 return k; 574 } 575 576 function Swap7(uint loopCount) returns (uint) { 577 uint i; 578 uint k = loopCount; 579 for (i = 1; i < loopCount; i++) { 580 assembly { swap7 swap7 } 581 } 582 return k; 583 } 584 585 function Swap8(uint loopCount) returns (uint) { 586 uint i; 587 uint k = loopCount; 588 for (i = 1; i < loopCount; i++) { 589 assembly { swap8 swap8 } 590 } 591 return k; 592 } 593 594 function Swap9(uint loopCount) returns (uint) { 595 uint i; 596 uint k = loopCount; 597 for (i = 1; i < loopCount; i++) { 598 assembly { swap9 swap9 } 599 } 600 return k; 601 } 602 603 function Swap10(uint loopCount) returns (uint) { 604 uint i; 605 uint k = loopCount; 606 for (i = 1; i < loopCount; i++) { 607 assembly { swap10 swap10 } 608 } 609 return k; 610 } 611 612 function Swap11(uint loopCount) returns (uint) { 613 uint i; 614 uint k = loopCount; 615 for (i = 1; i < loopCount; i++) { 616 assembly { swap11 swap11 } 617 } 618 return k; 619 } 620 621 function Swap12(uint loopCount) returns (uint) { 622 uint i; 623 uint k = loopCount; 624 for (i = 1; i < loopCount; i++) { 625 assembly { swap12 swap12 } 626 } 627 return k; 628 } 629 630 function Swap13(uint loopCount) returns (uint) { 631 uint i; 632 uint k = loopCount; 633 for (i = 1; i < loopCount; i++) { 634 assembly { swap13 swap13 } 635 } 636 return k; 637 } 638 639 function Swap14(uint loopCount) returns (uint) { 640 uint i; 641 uint k = loopCount; 642 for (i = 1; i < loopCount; i++) { 643 assembly { swap14 swap14 } 644 } 645 return k; 646 } 647 648 function Swap15(uint loopCount) returns (uint) { 649 uint i; 650 uint k = loopCount; 651 for (i = 1; i < loopCount; i++) { 652 assembly { swap15 swap15 } 653 } 654 return k; 655 } 656 657 function Swap16(uint loopCount) returns (uint) { 658 uint i; 659 uint k = loopCount; 660 for (i = 1; i < loopCount; i++) { 661 assembly { swap16 swap16 } 662 } 663 return k; 664 } 665 666 function Call(uint loopCount, address to) returns (uint) { 667 uint i; 668 uint k; 669 for(i = 0; i < loopCount; i++) { 670 assembly { 671 k := call(gas, to, 0, 0, 0, 0, 0) 672 } 673 } 674 return i; 675 } 676 677 function CallCode(uint loopCount, address to) returns (uint) { 678 uint i; 679 uint k; 680 for(i = 0; i < loopCount; i++) { 681 assembly { 682 k := callcode(gas, to, 0, 0, 0, 0, 0) 683 } 684 } 685 return i; 686 } 687 688 function StaticCall(uint loopCount, address to, bytes input) returns (uint) { 689 uint i; 690 uint k; 691 uint len = input.length; 692 for(i = 0; i < loopCount; i++) { 693 assembly { 694 k := staticcall(gas, to, add(input,0x20), len, 0, 0) 695 } 696 } 697 return k; 698 } 699 700 function DelegateCall(uint loopCount, address to) returns (uint) { 701 uint i; 702 uint k; 703 for(i = 0; i < loopCount; i++) { 704 assembly { 705 k := delegatecall(gas, to, 0, 0, 0, 0) 706 } 707 } 708 return i; 709 } 710 711 function Create(uint loopCount) returns (address) { 712 uint i; 713 address addr; 714 for(i = 0; i < loopCount; i++) { 715 StopContract c = new StopContract(); 716 addr = address(c); 717 } 718 return addr; 719 } 720 721 function Create2(uint loopCount, bytes code, uint salt) returns (address) { 722 uint i; 723 address addr; 724 uint codelen = code.length; 725 for(i = 0; i < loopCount; i++) { 726 assembly { 727 addr := create2(0, add(code,0x20), codelen, salt) 728 } 729 } 730 return addr; 731 } 732 733 function Sstore(uint loopCount, uint start) returns (uint) { 734 uint i; 735 uint k; 736 for (i = 0; i < loopCount; i++) { 737 testMap[start + i] = i; 738 } 739 return k; 740 } 741 742 function Sload(uint loopCount) returns (uint) { 743 uint i; 744 uint k; 745 for (i = 0; i < loopCount; i++) { 746 k = testMap[i]; 747 } 748 return k; 749 } 750 751 function Mstore(uint loopCount, uint memsize) returns (uint) { 752 uint i; 753 uint k; 754 uint[] memory arr = new uint[](memsize); 755 for (i = 0; i < loopCount; i++) { 756 arr[i%memsize] = i; 757 } 758 return arr[memsize-1]; 759 } 760 761 function Mload(uint loopCount, uint memsize) returns (uint) { 762 uint i; 763 uint k; 764 uint[] memory arr = new uint[](memsize); 765 for (i = 0; i < loopCount; i++) { 766 k = arr[i%memsize]; 767 } 768 return k; 769 } 770 771 function Msize(uint loopCount, uint memsize) returns (uint) { 772 uint i; 773 uint k; 774 uint[] memory arr = new uint[](memsize); 775 for (i = 0; i < loopCount; i++) { 776 assembly { 777 k := msize() 778 } 779 } 780 return k; 781 } 782 783 function Gas(uint loopCount) returns (uint) { 784 uint i; 785 uint k; 786 for (i = 0; i < loopCount; i++) { 787 assembly { 788 k := gas() 789 } 790 } 791 return k; 792 } 793 794 function Address(uint loopCount) returns (uint) { 795 uint i; 796 uint k; 797 for (i = 0; i < loopCount; i++) { 798 assembly { 799 k := address() 800 } 801 } 802 return k; 803 } 804 805 function Balance(uint loopCount, address addr) returns (uint) { 806 uint i; 807 uint k; 808 for (i = 0; i < loopCount; i++) { 809 assembly { 810 k := balance(addr) 811 } 812 } 813 return k; 814 } 815 816 function Caller(uint loopCount) returns (uint) { 817 uint i; 818 uint k; 819 for (i = 0; i < loopCount; i++) { 820 assembly { 821 k := caller() 822 } 823 } 824 return k; 825 } 826 827 function CallValue(uint loopCount) returns (uint) { 828 uint i; 829 uint k; 830 for (i = 0; i < loopCount; i++) { 831 assembly { 832 k := callvalue() 833 } 834 } 835 return k; 836 } 837 838 function CallDataLoad(uint loopCount) returns (uint) { 839 uint i; 840 uint k; 841 for (i = 0; i < loopCount; i++) { 842 assembly { 843 k := calldataload(i) 844 } 845 } 846 return k; 847 } 848 849 function CallDataSize(uint loopCount) returns (uint) { 850 uint i; 851 uint k; 852 for (i = 0; i < loopCount; i++) { 853 assembly { 854 k := calldatasize() 855 } 856 } 857 return k; 858 } 859 860 function CallDataCopy(uint loopCount, bytes data, uint size) returns (uint) { 861 uint i; 862 uint k; 863 uint[] memory arr = new uint[](size); 864 for (i = 0; i < loopCount; i++) { 865 assembly { 866 calldatacopy(arr, 0, size) 867 } 868 } 869 return k; 870 } 871 872 function CodeSize(uint loopCount) returns (uint) { 873 uint i; 874 uint k; 875 for (i = 0; i < loopCount; i++) { 876 assembly { 877 k := codesize() 878 } 879 } 880 return k; 881 } 882 883 function CodeCopy(uint loopCount, uint size) returns (uint) { 884 uint i; 885 uint k; 886 uint[] memory arr = new uint[](size); 887 for (i = 0; i < loopCount; i++) { 888 assembly { 889 codecopy(arr, 0, size) 890 } 891 } 892 return k; 893 } 894 895 function ExtCodeSize(uint loopCount, address addr) returns (uint) { 896 uint i; 897 uint k; 898 for (i = 0; i < loopCount; i++) { 899 assembly { 900 k := extcodesize(addr) 901 } 902 } 903 return k; 904 } 905 906 function ExtCodeCopy(uint loopCount, address addr, uint size) returns (uint) { 907 uint i; 908 uint k; 909 uint[] memory arr = new uint[](size); 910 for (i = 0; i < loopCount; i++) { 911 assembly { 912 extcodecopy(addr, arr, 0, size) 913 } 914 } 915 return k; 916 } 917 918 function ReturnDataSize(uint loopCount) returns (uint) { 919 uint i; 920 uint k; 921 for (i = 0; i < loopCount; i++) { 922 assembly { 923 k := returndatasize() 924 } 925 } 926 return k; 927 } 928 929 function ReturnDataCopy(uint loopCount, uint size, address addr) returns (uint) { 930 uint i; 931 uint k; 932 bytes memory arr2 = new bytes(size); 933 StopContract(addr).ReturnData(size); 934 assembly { 935 k := returndatasize 936 } 937 for (i = 0; i < loopCount; i++) { 938 assembly { 939 returndatacopy(arr2, 0, size) 940 } 941 } 942 return k; 943 } 944 945 function Log0(uint loopCount, bytes l) returns (uint) { 946 uint i; 947 uint k; 948 uint len = l.length; 949 for (i = 0; i < loopCount; i++) { 950 assembly { 951 log0(add(l,32), l) 952 } 953 } 954 return k; 955 } 956 957 function Log1(uint loopCount, bytes l, uint t1) returns (uint) { 958 uint i; 959 uint k; 960 uint len = l.length; 961 for (i = 0; i < loopCount; i++) { 962 assembly { 963 log1(add(l,32), l, t1) 964 } 965 } 966 return k; 967 } 968 969 function Log2(uint loopCount, bytes l, uint t1, uint t2) returns (uint) { 970 uint i; 971 uint k; 972 uint len = l.length; 973 for (i = 0; i < loopCount; i++) { 974 assembly { 975 log2(add(l,32), l, t1, t2) 976 } 977 } 978 return k; 979 } 980 981 function Log3(uint loopCount, bytes l, uint t1, uint t2, uint t3) returns (uint) { 982 uint i; 983 uint k; 984 uint len = l.length; 985 for (i = 0; i < loopCount; i++) { 986 assembly { 987 log3(add(l,32), l, t1, t2, t3) 988 } 989 } 990 return k; 991 } 992 993 function Log4(uint loopCount, bytes l, uint t1, uint t2, uint t3, uint t4) returns (uint) { 994 uint i; 995 uint k; 996 uint len = l.length; 997 for (i = 0; i < loopCount; i++) { 998 assembly { 999 log4(add(l,32), l, t1, t2, t3, t4) 1000 } 1001 } 1002 return k; 1003 } 1004 1005 function Origin(uint loopCount) returns (uint) { 1006 uint i; 1007 uint k; 1008 for (i = 0; i < loopCount; i++) { 1009 assembly { 1010 k := origin() 1011 } 1012 } 1013 return k; 1014 } 1015 1016 function GasPrice(uint loopCount) returns (uint) { 1017 uint i; 1018 uint k; 1019 for (i = 0; i < loopCount; i++) { 1020 assembly { 1021 k := gasprice() 1022 } 1023 } 1024 return k; 1025 } 1026 1027 function BlockHash(uint loopCount, uint blkNum) returns (uint) { 1028 uint i; 1029 uint k; 1030 for (i = 0; i < loopCount; i++) { 1031 assembly { 1032 k := blockhash(blkNum) 1033 } 1034 } 1035 return k; 1036 } 1037 1038 function Coinbase(uint loopCount) returns (uint) { 1039 uint i; 1040 uint k; 1041 for (i = 0; i < loopCount; i++) { 1042 assembly { 1043 k := coinbase() 1044 } 1045 } 1046 return k; 1047 } 1048 1049 function Timestamp(uint loopCount) returns (uint) { 1050 uint i; 1051 uint k; 1052 for (i = 0; i < loopCount; i++) { 1053 assembly { 1054 k := timestamp() 1055 } 1056 } 1057 return k; 1058 } 1059 1060 function Number(uint loopCount) returns (uint) { 1061 uint i; 1062 uint k; 1063 for (i = 0; i < loopCount; i++) { 1064 assembly { 1065 k := number() 1066 } 1067 } 1068 return k; 1069 } 1070 1071 function Difficulty(uint loopCount) returns (uint) { 1072 uint i; 1073 uint k; 1074 for (i = 0; i < loopCount; i++) { 1075 assembly { 1076 k := difficulty() 1077 } 1078 } 1079 return k; 1080 } 1081 1082 function GasLimit(uint loopCount) returns (uint) { 1083 uint i; 1084 uint k; 1085 for (i = 0; i < loopCount; i++) { 1086 assembly { 1087 k := gaslimit() 1088 } 1089 } 1090 return k; 1091 } 1092 1093 function Combination(uint loopCount, uint memsize) returns (uint) { 1094 uint i; 1095 uint k; 1096 uint[] memory arr = new uint[](memsize); 1097 for (i = 0; i < loopCount; i++) { 1098 k = k + i; 1099 arr[i%memsize] = i; 1100 testMap[i] = i; 1101 k = testMap[i]; 1102 k = k * i; 1103 k = arr[i%memsize]; 1104 k = k * i; 1105 } 1106 return k; 1107 } 1108 1109 function precompiledContractTest(uint loopCount, address addr, bytes input) returns (uint) { 1110 uint len = input.length; 1111 uint i; 1112 uint k; 1113 1114 for (i = 0; i < 100000; i++) { 1115 assembly { 1116 call(gas, addr, 0, add(input,0x20), len, 0, 0) 1117 pop 1118 } 1119 } 1120 1121 return k; 1122 } 1123 1124 }