Skip to content

Commit d10c8a0

Browse files
committed
Create Bench.java
1 parent 93989b5 commit d10c8a0

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

src/test/java/org/tdf/rlp/Bench.java

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package org.tdf.rlp;
2+
3+
import lombok.Getter;
4+
import lombok.SneakyThrows;
5+
import org.apache.commons.codec.binary.Hex;
6+
import org.junit.Test;
7+
8+
import java.math.BigInteger;
9+
import java.util.Arrays;
10+
11+
public class Bench {
12+
@Getter
13+
public static class PoolData{
14+
long chainId;
15+
byte[] address;
16+
long poolType;
17+
BigInteger f;
18+
BigInteger fm;
19+
BigInteger r;
20+
BigInteger rm;
21+
BigInteger debt;
22+
BigInteger price;
23+
long decimals;
24+
25+
public PoolData(){
26+
27+
}
28+
29+
30+
public PoolData(long chainId, byte[] address, long poolType, BigInteger f, BigInteger fm, BigInteger r, BigInteger rm, BigInteger debt, BigInteger price, long decimals) {
31+
this.chainId = chainId;
32+
this.address = address;
33+
this.poolType = poolType;
34+
this.f = f;
35+
this.fm = fm;
36+
this.r = r;
37+
this.rm = rm;
38+
this.debt = debt;
39+
this.price = price;
40+
this.decimals = decimals;
41+
}
42+
}
43+
44+
public static void main(String[] args) {
45+
benchEncodeDecode();
46+
}
47+
48+
@SneakyThrows
49+
public static void benchEncodeDecode() {
50+
String dt = "f90205f84e820539942c93e2f9f75382717af5de4c105ffb4c6503c5b4038a01605d9ee98627100000891b1ae4d6e2ef50000089f3f20b8dfa69d00000891b1ae4d6e2ef5000008089020281c283b028524012f182053994eb4d5af9f8cbb97f6eb95c21f2ff541b121c7fd1018814d1120d7b160000808080808923b97412d86c4ea13a12f84d8205399444915ecba748148cf6ad6a323af8be52d3befb8f01890ad78ebc5ac6200000890ad78ebc5ac6200000890ad78ebc5ac6200000890ad78ebc5ac62000008089d5c457fd13c65daff712f84e8205399434451604347d45ef4b5cbd790e88d09907b1706c0189055005f0c61448000089055005f0c6144800008915af1d78b58c4000008915af1d78b58c400000808a0df94d0efa177fd1a51812f8508205399438e4f0437edd9bda6f32caae007c985b97bbcff1808a01a46d2eef9995fe00008a010ec78cd35b142c00008a010f0cf064dd592000008a010f0cf064dd5920000080880de0b6b3a764000012f85082053994c7376932e8f7f03d33ffb3ed781d7f28c6c5bbb5808a01c37637845d6d2000008a010ec78cd35b142c00008a0202fefbf2d7c2f000008a010f0cf064dd5920000080880de0b6b3a764000012f83e820539945b536881e3c4fd7639ca0dcaeffcd73daff98523028a021e19e0c9bab24000008a021e19e0c9bab24000008a021e19e0c9bab240000080808012";
51+
byte[] bytes = Hex.decodeHex(dt);
52+
53+
PoolData[] datas = RLPCodec.decode(bytes, PoolData[].class);
54+
55+
int count = 1000000;
56+
57+
long now = System.currentTimeMillis();
58+
59+
for(int i = 0; i < count; i++) {
60+
RLPCodec.encode(datas);
61+
}
62+
63+
long end = System.currentTimeMillis();
64+
65+
66+
System.out.println("encode " + count + " times " + ((end - now) * 1.0 / count) + " ms avg");
67+
68+
now = System.currentTimeMillis();
69+
70+
for(int i = 0; i < count; i++) {
71+
RLPCodec.decode(bytes, PoolData[].class);
72+
}
73+
74+
end = System.currentTimeMillis();
75+
76+
System.out.println("decode " + count + " times " + ((end - now) * 1.0 / count) + " ms avg");
77+
78+
}
79+
}

0 commit comments

Comments
 (0)