forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR cosmos#3005: Move auth keeper benchmarks to sep. file
- Loading branch information
1 parent
a3d5e49
commit f11a65d
Showing
2 changed files
with
116 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package auth | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
abci "github.com/tendermint/tendermint/abci/types" | ||
"github.com/tendermint/tendermint/libs/log" | ||
) | ||
|
||
func BenchmarkAccountMapperGetAccountFound(b *testing.B) { | ||
ms, capKey, _ := setupMultiStore() | ||
cdc := codec.New() | ||
RegisterBaseAccount(cdc) | ||
|
||
// make context and mapper | ||
ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger()) | ||
mapper := NewAccountKeeper(cdc, capKey, ProtoBaseAccount) | ||
|
||
// 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 := mapper.NewAccountWithAddress(ctx, addr) | ||
mapper.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)} | ||
mapper.GetAccount(ctx, sdk.AccAddress(arr)) | ||
} | ||
} | ||
|
||
func BenchmarkAccountMapperGetAccountFoundWithCoins(b *testing.B) { | ||
ms, capKey, _ := setupMultiStore() | ||
cdc := codec.New() | ||
RegisterBaseAccount(cdc) | ||
|
||
// make context and mapper | ||
ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger()) | ||
mapper := NewAccountKeeper(cdc, capKey, ProtoBaseAccount) | ||
|
||
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 := mapper.NewAccountWithAddress(ctx, addr) | ||
acc.SetCoins(coins) | ||
mapper.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)} | ||
mapper.GetAccount(ctx, sdk.AccAddress(arr)) | ||
} | ||
} | ||
|
||
func BenchmarkAccountMapperSetAccount(b *testing.B) { | ||
ms, capKey, _ := setupMultiStore() | ||
cdc := codec.New() | ||
RegisterBaseAccount(cdc) | ||
|
||
// make context and mapper | ||
ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger()) | ||
mapper := NewAccountKeeper(cdc, capKey, ProtoBaseAccount) | ||
|
||
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 := mapper.NewAccountWithAddress(ctx, addr) | ||
mapper.SetAccount(ctx, acc) | ||
} | ||
} | ||
|
||
func BenchmarkAccountMapperSetAccountWithCoins(b *testing.B) { | ||
ms, capKey, _ := setupMultiStore() | ||
cdc := codec.New() | ||
RegisterBaseAccount(cdc) | ||
|
||
// make context and mapper | ||
ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger()) | ||
mapper := NewAccountKeeper(cdc, capKey, ProtoBaseAccount) | ||
|
||
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 := mapper.NewAccountWithAddress(ctx, addr) | ||
acc.SetCoins(coins) | ||
mapper.SetAccount(ctx, acc) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters