-
Notifications
You must be signed in to change notification settings - Fork 160
/
data.sol
110 lines (89 loc) · 3.05 KB
/
data.sol
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
pragma solidity ^0.4.16;
pragma experimental "v0.5.0";
pragma experimental "ABIEncoderV2";
import {Data} from "../../src/patricia_tree/Data.sol";
import {STLPerf} from "../STLPerf.sol";
contract PatriciaTreeDataPerf is STLPerf {
using Data for Data.Node;
using Data for Data.Edge;
using Data for Data.Label;
uint internal constant MAX_LENGTH = 256;
uint internal constant UINT256_ZEROES = 0;
uint internal constant UINT256_ONES = ~uint(0);
bytes32 internal constant B32_ZEROES = bytes32(UINT256_ZEROES);
bytes32 internal constant B32_ONES = bytes32(UINT256_ONES);
}
contract PerfPatriciaTreeDataChopFirstBit is PatriciaTreeDataPerf {
function perf() public payable returns (uint) {
var lbl = Data.Label(0, 1);
uint gasPre = msg.gas;
lbl.chopFirstBit();
uint gasPost = msg.gas;
return gasPre - gasPost;
}
}
contract PerfPatriciaTreeDataRemovePrefix is PatriciaTreeDataPerf {
function perf() public payable returns (uint) {
var lbl = Data.Label(0, 5);
uint gasPre = msg.gas;
lbl.removePrefix(5);
uint gasPost = msg.gas;
return gasPre - gasPost;
}
}
contract PerfPatriciaTreeDataCommonPrefixLengthZero is PatriciaTreeDataPerf {
function perf() public payable returns (uint) {
var lbl = Data.Label(B32_ZEROES, 0);
uint gasPre = msg.gas;
lbl.commonPrefix(lbl);
uint gasPost = msg.gas;
return gasPre - gasPost;
}
}
contract PerfPatriciaTreeDataCommonPrefixNoMatch is PatriciaTreeDataPerf {
function perf() public payable returns (uint) {
var lbl = Data.Label(B32_ZEROES, 256);
var lbl2 = Data.Label(B32_ONES, 256);
uint gasPre = msg.gas;
lbl.commonPrefix(lbl2);
uint gasPost = msg.gas;
return gasPre - gasPost;
}
}
contract PerfPatriciaTreeDataCommonPrefixFullMatch is PatriciaTreeDataPerf {
function perf() public payable returns (uint) {
var lbl = Data.Label(B32_ZEROES, 256);
uint gasPre = msg.gas;
lbl.commonPrefix(lbl);
uint gasPost = msg.gas;
return gasPre - gasPost;
}
}
contract PerfPatriciaTreeDataSplitAtPositionZero is PatriciaTreeDataPerf {
function perf() public payable returns (uint) {
var lbl = Data.Label(B32_ZEROES, 256);
uint gasPre = msg.gas;
lbl.splitAt(0);
uint gasPost = msg.gas;
return gasPre - gasPost;
}
}
contract PerfPatriciaTreeDataSplitAt is PatriciaTreeDataPerf {
function perf() public payable returns (uint) {
var lbl = Data.Label(B32_ZEROES, 256);
uint gasPre = msg.gas;
lbl.splitAt(55);
uint gasPost = msg.gas;
return gasPre - gasPost;
}
}
contract PerfPatriciaTreeDataSplitCommonPrefix is PatriciaTreeDataPerf {
function perf() public payable returns (uint) {
var lbl = Data.Label(B32_ZEROES, 256);
var lbl2 = Data.Label(0x1111, 256);
uint gasPre = msg.gas;
lbl.splitCommonPrefix(lbl2);
uint gasPost = msg.gas;
return gasPre - gasPost;
}
}