refactor: use b.Loop() to simplify the code and improve performance (#25367)

Signed-off-by: withtimezone <with_timezone@outlook.com>
This commit is contained in:
withtimezone 2025-09-25 23:36:28 +08:00 committed by GitHub
parent 04a1287e92
commit 39c56716bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 4 deletions

View File

@ -39,8 +39,7 @@ func benchmarkValidateGenesis(b *testing.B, n int) {
validators = append(validators, validator)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
genesisState := types.DefaultGenesisState()
genesisState.Validators = validators
if err := staking.ValidateGenesis(genesisState); err != nil {

View File

@ -50,8 +50,8 @@ func BenchmarkApplyAndReturnValidatorSetUpdates(b *testing.B) {
require.NoError(b, keeper.SetLastValidatorPower(ctx, valAddrs[i], validator.ConsensusPower(sdk.DefaultPowerReduction)))
}
ctx, _ = testEnv.ctx.CacheContext()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_, _ = keeper.ApplyAndReturnValidatorSetUpdates(ctx)
}
}