cosmos-sdk/x/staking/keeper/validator_bench_test.go
Riccardo Montagnin 090411a7b5
Removed GetValidator caching to fix concurrency error (#8546)
* Removed GetValidator caching to fix concurrency error

* Fixed linting and added CHANGELOG entry

* Moved benchmark test into its own file

* Moved CHANGELOG entry to bug fix

* Update CHANGELOG.md

Co-authored-by: Cory <cjlevinson@gmail.com>

Co-authored-by: Amaury <amaury.martiny@protonmail.com>
Co-authored-by: Cory <cjlevinson@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2021-02-12 11:52:03 +00:00

30 lines
700 B
Go

package keeper_test
import "testing"
func BenchmarkGetValidator(b *testing.B) {
// 900 is the max number we are allowed to use in order to avoid simapp.CreateTestPubKeys
// panic: encoding/hex: odd length hex string
var powersNumber = 900
var totalPower int64 = 0
var powers = make([]int64, powersNumber)
for i := range powers {
powers[i] = int64(i)
totalPower += int64(i)
}
app, ctx, _, valAddrs, vals := initValidators(b, totalPower, len(powers), powers)
for _, validator := range vals {
app.StakingKeeper.SetValidator(ctx, validator)
}
b.ResetTimer()
for n := 0; n < b.N; n++ {
for _, addr := range valAddrs {
_, _ = app.StakingKeeper.GetValidator(ctx, addr)
}
}
}