2019-08-15 08:19:16 -07:00
|
|
|
package keeper_test
|
2018-12-06 01:49:30 -08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-12-10 06:27:25 -08:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2018-12-06 01:49:30 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
func BenchmarkAccountMapperGetAccountFound(b *testing.B) {
|
2019-08-15 08:19:16 -07:00
|
|
|
app, ctx := createTestApp(false)
|
2018-12-06 01:49:30 -08:00
|
|
|
|
|
|
|
// 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)
|
2019-08-15 08:19:16 -07:00
|
|
|
acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr)
|
|
|
|
app.AccountKeeper.SetAccount(ctx, acc)
|
2018-12-06 01:49:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
arr := []byte{byte((i & 0xFF0000) >> 16), byte((i & 0xFF00) >> 8), byte(i & 0xFF)}
|
2019-08-15 08:19:16 -07:00
|
|
|
app.AccountKeeper.GetAccount(ctx, sdk.AccAddress(arr))
|
2018-12-06 01:49:30 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkAccountMapperGetAccountFoundWithCoins(b *testing.B) {
|
2019-08-15 08:19:16 -07:00
|
|
|
app, ctx := createTestApp(false)
|
|
|
|
|
2018-12-06 01:49:30 -08:00
|
|
|
coins := sdk.Coins{
|
2019-10-10 08:53:30 -07:00
|
|
|
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)),
|
2018-12-06 01:49:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
2019-08-15 08:19:16 -07:00
|
|
|
acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr)
|
2018-12-06 01:49:30 -08:00
|
|
|
acc.SetCoins(coins)
|
2019-08-15 08:19:16 -07:00
|
|
|
app.AccountKeeper.SetAccount(ctx, acc)
|
2018-12-06 01:49:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
arr := []byte{byte((i & 0xFF0000) >> 16), byte((i & 0xFF00) >> 8), byte(i & 0xFF)}
|
2019-08-15 08:19:16 -07:00
|
|
|
app.AccountKeeper.GetAccount(ctx, sdk.AccAddress(arr))
|
2018-12-06 01:49:30 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkAccountMapperSetAccount(b *testing.B) {
|
2019-08-15 08:19:16 -07:00
|
|
|
app, ctx := createTestApp(false)
|
2018-12-06 01:49:30 -08:00
|
|
|
|
|
|
|
b.ResetTimer()
|
2018-12-20 11:09:43 -08:00
|
|
|
|
2018-12-06 01:49:30 -08:00
|
|
|
// 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)
|
2019-08-15 08:19:16 -07:00
|
|
|
acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr)
|
|
|
|
app.AccountKeeper.SetAccount(ctx, acc)
|
2018-12-06 01:49:30 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkAccountMapperSetAccountWithCoins(b *testing.B) {
|
2019-08-15 08:19:16 -07:00
|
|
|
app, ctx := createTestApp(false)
|
|
|
|
|
2018-12-06 01:49:30 -08:00
|
|
|
coins := sdk.Coins{
|
2019-10-10 08:53:30 -07:00
|
|
|
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)),
|
2018-12-06 01:49:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
b.ResetTimer()
|
2018-12-20 11:09:43 -08:00
|
|
|
|
2018-12-06 01:49:30 -08:00
|
|
|
// 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)
|
2019-08-15 08:19:16 -07:00
|
|
|
acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr)
|
2018-12-06 01:49:30 -08:00
|
|
|
acc.SetCoins(coins)
|
2019-08-15 08:19:16 -07:00
|
|
|
app.AccountKeeper.SetAccount(ctx, acc)
|
2018-12-06 01:49:30 -08:00
|
|
|
}
|
|
|
|
}
|