-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Closed
Description
Current situation
Some files are already updated (22 files), but we still have 19 files with the old pattern (33 total occurrences). It's inconsistent and we should fix it.
Why this matters
The Go team recommends using b.Loop() now instead of the manual for loop. Benefits:
- Better performance measurement accuracy
- Cleaner code that's easier to read
- Follows modern Go practices
Files that need updating
Found these with the old pattern:
x/bank/types/balance_test.gox/auth/keeper/keeper_bench_test.go(2 places)tools/cosmovisor/args_test.gotests/integration/tx/benchmark/benchmarks_test.gostore/rootmulti/snapshot_test.go(2 places)store/internal/maps/bench_test.gostore/internal/conv/string_test.gostore/cachekv/search_benchmark_test.gostore/cachekv/benchmark_test.gostore/cache/benchmark_test.gomath/legacy_dec_test.go(8 places - this one has a lot)math/int_test.go(2 places)internal/conv/string_test.gocrypto/types/compact_bit_array_test.gocrypto/keys/internal/benchmarking/bench.go(3 places)crypto/armor_test.gocontrib/x/nft/internal/conv/string_test.gocodec/unknownproto/benchmarks_test.go(2 places)codec/types/any_test.go
The change is simple
// Old way:
for i := 0; i < b.N; i++ {
// benchmark code
}
// New way:
for b.Loop() {
// benchmark code
}
// Special case when you need the index:
for i := 0; b.Loop(); i++ {
// benchmark code that uses i
}Testing plan
Before making changes:
go test -bench=. -benchmem ./... > before.txtAfter changes:
go test -bench=. -benchmem ./... > after.txtThen compare the results to make sure nothing broke and performance improved.
References
Metadata
Metadata
Assignees
Labels
No labels