-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Expand file tree
/
Copy pathkeeper_bench_test.go
More file actions
67 lines (55 loc) · 1.68 KB
/
Copy pathkeeper_bench_test.go
File metadata and controls
67 lines (55 loc) · 1.68 KB
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
package keeper_test
import (
"testing"
"github.com/stretchr/testify/require"
"cosmossdk.io/depinject"
"cosmossdk.io/log"
authTest "github.com/cosmos/cosmos-sdk/tests/integration/auth/keeper"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/keeper"
)
func BenchmarkAccountMapperGetAccountFound(b *testing.B) {
b.ReportAllocs()
var accountKeeper keeper.AccountKeeper
app, err := simtestutil.Setup(
depinject.Configs(
depinject.Supply(log.NewNopLogger()),
authTest.AppConfig,
),
&accountKeeper,
)
require.NoError(b, err)
ctx := app.BaseApp.NewContext(false)
// 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 := accountKeeper.NewAccountWithAddress(ctx, addr)
accountKeeper.SetAccount(ctx, acc)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
arr := []byte{byte((i & 0xFF0000) >> 16), byte((i & 0xFF00) >> 8), byte(i & 0xFF)}
accountKeeper.GetAccount(ctx, sdk.AccAddress(arr))
}
}
func BenchmarkAccountMapperSetAccount(b *testing.B) {
b.ReportAllocs()
var accountKeeper keeper.AccountKeeper
app, err := simtestutil.Setup(
depinject.Configs(
depinject.Supply(log.NewNopLogger()),
authTest.AppConfig,
), &accountKeeper)
require.NoError(b, err)
ctx := app.BaseApp.NewContext(false)
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 := accountKeeper.NewAccountWithAddress(ctx, addr)
accountKeeper.SetAccount(ctx, acc)
}
}