forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keeper_bench_test.go
89 lines (75 loc) · 2.43 KB
/
keeper_bench_test.go
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
package auth
import (
"testing"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func BenchmarkAccountMapperGetAccountFound(b *testing.B) {
input := setupTestInput()
// assumes b.N < 2**24
for i := 0; i < b.N; i++ {
arr := []byte{byte((i & 0xFF0000) >> 16), byte((i & 0xFF00) >> 8), byte(i & 0xFF)}
addr := sdk.AccAddress(arr)
acc := input.ak.NewAccountWithAddress(input.ctx, addr)
input.ak.SetAccount(input.ctx, acc)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
arr := []byte{byte((i & 0xFF0000) >> 16), byte((i & 0xFF00) >> 8), byte(i & 0xFF)}
input.ak.GetAccount(input.ctx, sdk.AccAddress(arr))
}
}
func BenchmarkAccountMapperGetAccountFoundWithCoins(b *testing.B) {
input := setupTestInput()
coins := sdk.Coins{
sdk.NewCoin("LTC", sdk.NewInt(1000)),
sdk.NewCoin("BTC", sdk.NewInt(1000)),
sdk.NewCoin("ETH", sdk.NewInt(1000)),
sdk.NewCoin("XRP", sdk.NewInt(1000)),
sdk.NewCoin("BCH", sdk.NewInt(1000)),
sdk.NewCoin("EOS", sdk.NewInt(1000)),
}
// assumes b.N < 2**24
for i := 0; i < b.N; i++ {
arr := []byte{byte((i & 0xFF0000) >> 16), byte((i & 0xFF00) >> 8), byte(i & 0xFF)}
addr := sdk.AccAddress(arr)
acc := input.ak.NewAccountWithAddress(input.ctx, addr)
acc.SetCoins(coins)
input.ak.SetAccount(input.ctx, acc)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
arr := []byte{byte((i & 0xFF0000) >> 16), byte((i & 0xFF00) >> 8), byte(i & 0xFF)}
input.ak.GetAccount(input.ctx, sdk.AccAddress(arr))
}
}
func BenchmarkAccountMapperSetAccount(b *testing.B) {
input := setupTestInput()
b.ResetTimer()
// assumes b.N < 2**24
for i := 0; i < b.N; i++ {
arr := []byte{byte((i & 0xFF0000) >> 16), byte((i & 0xFF00) >> 8), byte(i & 0xFF)}
addr := sdk.AccAddress(arr)
acc := input.ak.NewAccountWithAddress(input.ctx, addr)
input.ak.SetAccount(input.ctx, acc)
}
}
func BenchmarkAccountMapperSetAccountWithCoins(b *testing.B) {
input := setupTestInput()
coins := sdk.Coins{
sdk.NewCoin("LTC", sdk.NewInt(1000)),
sdk.NewCoin("BTC", sdk.NewInt(1000)),
sdk.NewCoin("ETH", sdk.NewInt(1000)),
sdk.NewCoin("XRP", sdk.NewInt(1000)),
sdk.NewCoin("BCH", sdk.NewInt(1000)),
sdk.NewCoin("EOS", sdk.NewInt(1000)),
}
b.ResetTimer()
// assumes b.N < 2**24
for i := 0; i < b.N; i++ {
arr := []byte{byte((i & 0xFF0000) >> 16), byte((i & 0xFF00) >> 8), byte(i & 0xFF)}
addr := sdk.AccAddress(arr)
acc := input.ak.NewAccountWithAddress(input.ctx, addr)
acc.SetCoins(coins)
input.ak.SetAccount(input.ctx, acc)
}
}