Skip to content

Commit

Permalink
Merge PR cosmos#3005: Move auth keeper benchmarks to sep. file
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez authored and cwgoes committed Dec 6, 2018
1 parent a3d5e49 commit f11a65d
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 106 deletions.
116 changes: 116 additions & 0 deletions x/auth/keeper_bench_test.go
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)
}
}
106 changes: 0 additions & 106 deletions x/auth/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,109 +96,3 @@ func TestAccountMapperRemoveAccount(t *testing.T) {
require.NotNil(t, acc2)
require.Equal(t, accSeq2, acc2.GetSequence())
}

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)
}
}

0 comments on commit f11a65d

Please sign in to comment.