cosmos-sdk/x/bank/bench_test.go

97 lines
2.9 KiB
Go
Raw Normal View History

package bank_test
import (
"testing"
2020-01-30 13:31:16 -08:00
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
2019-08-19 06:29:17 -07:00
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/types"
2019-08-19 06:29:17 -07:00
"github.com/cosmos/cosmos-sdk/x/staking"
)
var moduleAccAddr = auth.NewModuleAddress(staking.BondedPoolName)
func BenchmarkOneBankSendTxPerBlock(b *testing.B) {
// Add an account at genesis
acc := auth.BaseAccount{
Address: addr1,
}
2020-01-30 13:31:16 -08:00
// construct genesis state
genAccs := []types.GenesisAccount{&acc}
2019-08-19 06:29:17 -07:00
benchmarkApp := simapp.SetupWithGenesisAccounts(genAccs)
2020-01-30 13:31:16 -08:00
ctx := benchmarkApp.BaseApp.NewContext(false, abci.Header{})
// some value conceivably higher than the benchmarks would ever go
err := benchmarkApp.BankKeeper.SetBalances(ctx, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 100000000000)))
require.NoError(b, err)
benchmarkApp.Commit()
2019-08-19 06:29:17 -07:00
// Precompute all txs
2019-08-19 06:29:17 -07:00
txs := simapp.GenSequenceOfTxs([]sdk.Msg{sendMsg1}, []uint64{0}, []uint64{uint64(0)}, b.N, priv1)
b.ResetTimer()
2020-01-30 13:31:16 -08:00
height := int64(3)
// Run this with a profiler, so its easy to distinguish what time comes from
// Committing, and what time comes from Check/Deliver Tx.
for i := 0; i < b.N; i++ {
2020-01-30 13:31:16 -08:00
benchmarkApp.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{Height: height}})
_, _, err := benchmarkApp.Check(txs[i])
if err != nil {
panic("something is broken in checking transaction")
}
_, _, err = benchmarkApp.Deliver(txs[i])
require.NoError(b, err)
2020-01-30 13:31:16 -08:00
benchmarkApp.EndBlock(abci.RequestEndBlock{Height: height})
benchmarkApp.Commit()
2020-01-30 13:31:16 -08:00
height++
}
}
func BenchmarkOneBankMultiSendTxPerBlock(b *testing.B) {
// Add an account at genesis
acc := auth.BaseAccount{
Address: addr1,
}
// Construct genesis state
genAccs := []types.GenesisAccount{&acc}
2019-08-19 06:29:17 -07:00
benchmarkApp := simapp.SetupWithGenesisAccounts(genAccs)
2020-01-30 13:31:16 -08:00
ctx := benchmarkApp.BaseApp.NewContext(false, abci.Header{})
// some value conceivably higher than the benchmarks would ever go
err := benchmarkApp.BankKeeper.SetBalances(ctx, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 100000000000)))
require.NoError(b, err)
benchmarkApp.Commit()
2019-08-19 06:29:17 -07:00
// Precompute all txs
2019-08-19 06:29:17 -07:00
txs := simapp.GenSequenceOfTxs([]sdk.Msg{multiSendMsg1}, []uint64{0}, []uint64{uint64(0)}, b.N, priv1)
b.ResetTimer()
2020-01-30 13:31:16 -08:00
height := int64(3)
// Run this with a profiler, so its easy to distinguish what time comes from
// Committing, and what time comes from Check/Deliver Tx.
for i := 0; i < b.N; i++ {
2020-01-30 13:31:16 -08:00
benchmarkApp.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{Height: height}})
_, _, err := benchmarkApp.Check(txs[i])
if err != nil {
panic("something is broken in checking transaction")
}
_, _, err = benchmarkApp.Deliver(txs[i])
require.NoError(b, err)
2020-01-30 13:31:16 -08:00
benchmarkApp.EndBlock(abci.RequestEndBlock{Height: height})
benchmarkApp.Commit()
2020-01-30 13:31:16 -08:00
height++
}
}