aboutsummaryrefslogtreecommitdiffstats
path: root/src/VMTestsFiller/loop-exp.sol
blob: e42ddecf10101bd38eeaea0509f9e5c24de05c5f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
pragma solidity ^0.4;

contract ExpPerformanceTester {

    function testExp(int exponent, int seed, uint n) external returns (int) {
        int e = seed;
        for (uint i = 0; i < n; i += 1) {
            e = e ** exponent;
        }
        return e;
    }

    function testExpUnroll16(int exponent, int seed, uint n) external returns (int) {
        int e = seed;
        for (uint i = 0; i < n; i += 16) {
            e = e ** exponent;
            e = e ** exponent;
            e = e ** exponent;
            e = e ** exponent;
            e = e ** exponent;
            e = e ** exponent;
            e = e ** exponent;
            e = e ** exponent;
            e = e ** exponent;
            e = e ** exponent;
            e = e ** exponent;
            e = e ** exponent;
            e = e ** exponent;
            e = e ** exponent;
            e = e ** exponent;
            e = e ** exponent;
        }
        return e;
    }

    function testNop(int exponent, int seed, uint n) external returns (int) {
        for (uint i = 0; i < n; i += 1) {}
        return seed;
    }

    function testNopUnroll16(int exponent, int seed, uint n) external returns (int) {
        for (uint i = 0; i < n; i += 16) {}
        return seed;
    }
}