diff --git a/common/bitutil/compress_test.go b/common/bitutil/compress_test.go index c6f6fe8bcf0..0edd3a790b0 100644 --- a/common/bitutil/compress_test.go +++ b/common/bitutil/compress_test.go @@ -180,7 +180,7 @@ func benchmarkEncoding(b *testing.B, bytes int, fill float64) { // Reset the benchmark and measure encoding/decoding b.ResetTimer() b.ReportAllocs() - for i := 0; i < b.N; i++ { + for range b.Loop() { bitsetDecodeBytes(bitsetEncodeBytes(data), len(data)) } } diff --git a/common/hexutil/hexutil_test.go b/common/hexutil/hexutil_test.go index f2b800d82c9..814eac896a3 100644 --- a/common/hexutil/hexutil_test.go +++ b/common/hexutil/hexutil_test.go @@ -207,7 +207,7 @@ func BenchmarkEncodeBig(b *testing.B) { b.Run(bench.want, func(b *testing.B) { b.ReportAllocs() bigint := bench.input.(*big.Int) - for i := 0; i < b.N; i++ { + for range b.Loop() { EncodeBig(bigint) } }) diff --git a/common/hexutil/json_test.go b/common/hexutil/json_test.go index 3dc19680f98..b15752786be 100644 --- a/common/hexutil/json_test.go +++ b/common/hexutil/json_test.go @@ -100,7 +100,7 @@ func TestUnmarshalBytes(t *testing.T) { func BenchmarkUnmarshalBytes(b *testing.B) { input := []byte(`"0x123456789abcdef123456789abcdef"`) - for i := 0; i < b.N; i++ { + for range b.Loop() { var v Bytes if err := v.UnmarshalJSON(input); err != nil { b.Fatal(err) @@ -239,7 +239,7 @@ func TestUnmarshalU256(t *testing.T) { func BenchmarkUnmarshalBig(b *testing.B) { input := []byte(`"0x123456789abcdef123456789abcdef"`) - for i := 0; i < b.N; i++ { + for range b.Loop() { var v Big if err := v.UnmarshalJSON(input); err != nil { b.Fatal(err) @@ -305,7 +305,7 @@ func TestUnmarshalUint64(t *testing.T) { func BenchmarkUnmarshalUint64(b *testing.B) { input := []byte(`"0x123456789abcdf"`) - for i := 0; i < b.N; i++ { + for range b.Loop() { var v Uint64 v.UnmarshalJSON(input) }