Skip to content

Commit

Permalink
Moved benchmark test into its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
RiccardoM committed Feb 9, 2021
1 parent cd1035a commit 7123061
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
29 changes: 29 additions & 0 deletions x/staking/keeper/validator_bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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)
}
}
}
26 changes: 0 additions & 26 deletions x/staking/keeper/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,6 @@ func initValidators(t testing.TB, power int64, numAddrs int, powers []int64) (*s
return app, ctx, addrs, valAddrs, vs
}

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

func TestSetValidator(t *testing.T) {
app, ctx, _, _ := bootstrapValidatorTest(t, 10, 100)

Expand Down

0 comments on commit 7123061

Please sign in to comment.