Skip to content

Commit 1982352

Browse files
committed
core/types: using testing.B.Loop
1 parent 6492751 commit 1982352

File tree

5 files changed

+15
-16
lines changed

5 files changed

+15
-16
lines changed

core/types/block_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,7 @@ var benchBuffer = bytes.NewBuffer(make([]byte, 0, 32000))
264264
func BenchmarkEncodeBlock(b *testing.B) {
265265
block := makeBenchBlock()
266266
b.ResetTimer()
267-
268-
for i := 0; i < b.N; i++ {
267+
for b.Loop() {
269268
benchBuffer.Reset()
270269
if err := rlp.Encode(benchBuffer, block); err != nil {
271270
b.Fatal(err)

core/types/bloom9_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ func TestBloomExtensively(t *testing.T) {
7878

7979
func BenchmarkBloom9(b *testing.B) {
8080
test := []byte("testestestest")
81-
for i := 0; i < b.N; i++ {
81+
for b.Loop() {
8282
Bloom9(test)
8383
}
8484
}
8585

8686
func BenchmarkBloom9Lookup(b *testing.B) {
8787
toTest := []byte("testtest")
8888
bloom := new(Bloom)
89-
for i := 0; i < b.N; i++ {
89+
for b.Loop() {
9090
bloom.Test(toTest)
9191
}
9292
}
@@ -128,7 +128,7 @@ func BenchmarkCreateBloom(b *testing.B) {
128128
}
129129
b.Run("small-createbloom", func(b *testing.B) {
130130
b.ReportAllocs()
131-
for i := 0; i < b.N; i++ {
131+
for b.Loop() {
132132
for _, receipt := range rSmall {
133133
receipt.Bloom = CreateBloom(receipt)
134134
}
@@ -144,7 +144,7 @@ func BenchmarkCreateBloom(b *testing.B) {
144144
})
145145
b.Run("large-createbloom", func(b *testing.B) {
146146
b.ReportAllocs()
147-
for i := 0; i < b.N; i++ {
147+
for b.Loop() {
148148
for _, receipt := range rLarge {
149149
receipt.Bloom = CreateBloom(receipt)
150150
}
@@ -166,7 +166,7 @@ func BenchmarkCreateBloom(b *testing.B) {
166166
b.ResetTimer()
167167

168168
var bl Bloom
169-
for i := 0; i < b.N; i++ {
169+
for b.Loop() {
170170
bl = MergeBloom(rSmall)
171171
}
172172
b.StopTimer()
@@ -185,7 +185,7 @@ func BenchmarkCreateBloom(b *testing.B) {
185185
b.ResetTimer()
186186

187187
var bl Bloom
188-
for i := 0; i < b.N; i++ {
188+
for b.Loop() {
189189
bl = MergeBloom(rLarge)
190190
}
191191
b.StopTimer()

core/types/hashing_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ func BenchmarkDeriveSha200(b *testing.B) {
8686
b.Run("std_trie", func(b *testing.B) {
8787
b.ResetTimer()
8888
b.ReportAllocs()
89-
for i := 0; i < b.N; i++ {
89+
for b.Loop() {
9090
exp = types.DeriveSha(txs, trie.NewEmpty(triedb.NewDatabase(rawdb.NewMemoryDatabase(), nil)))
9191
}
9292
})
9393

9494
b.Run("stack_trie", func(b *testing.B) {
9595
b.ResetTimer()
9696
b.ReportAllocs()
97-
for i := 0; i < b.N; i++ {
97+
for b.Loop() {
9898
got = types.DeriveSha(txs, trie.NewStackTrie(nil))
9999
}
100100
})

core/types/transaction_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ func BenchmarkHash(b *testing.B) {
591591
GasTipCap: big.NewInt(500),
592592
GasFeeCap: big.NewInt(500),
593593
})
594-
for i := 0; i < b.N; i++ {
594+
for b.Loop() {
595595
signer.Hash(tx)
596596
}
597597
}
@@ -614,7 +614,7 @@ func BenchmarkEffectiveGasTip(b *testing.B) {
614614

615615
b.Run("Original", func(b *testing.B) {
616616
b.ReportAllocs()
617-
for i := 0; i < b.N; i++ {
617+
for b.Loop() {
618618
_, err := tx.EffectiveGasTip(baseFee.ToBig())
619619
if err != nil {
620620
b.Fatal(err)
@@ -625,7 +625,7 @@ func BenchmarkEffectiveGasTip(b *testing.B) {
625625
b.Run("IntoMethod", func(b *testing.B) {
626626
b.ReportAllocs()
627627
dst := new(uint256.Int)
628-
for i := 0; i < b.N; i++ {
628+
for b.Loop() {
629629
err := tx.calcEffectiveGasTip(dst, baseFee)
630630
if err != nil {
631631
b.Fatal(err)
@@ -729,7 +729,7 @@ func BenchmarkEffectiveGasTipCmp(b *testing.B) {
729729

730730
b.Run("Original", func(b *testing.B) {
731731
b.ReportAllocs()
732-
for i := 0; i < b.N; i++ {
732+
for b.Loop() {
733733
tx.EffectiveGasTipCmp(other, baseFee)
734734
}
735735
})

core/types/types_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func benchRLP(b *testing.B, encode bool) {
126126
b.Run(tc.name, func(b *testing.B) {
127127
b.ReportAllocs()
128128
var null = &devnull{}
129-
for i := 0; i < b.N; i++ {
129+
for b.Loop() {
130130
rlp.Encode(null, tc.obj)
131131
}
132132
b.SetBytes(int64(null.len / b.N))
@@ -136,7 +136,7 @@ func benchRLP(b *testing.B, encode bool) {
136136
// Test decoding
137137
b.Run(tc.name, func(b *testing.B) {
138138
b.ReportAllocs()
139-
for i := 0; i < b.N; i++ {
139+
for b.Loop() {
140140
if err := rlp.DecodeBytes(data, tc.obj); err != nil {
141141
b.Fatal(err)
142142
}

0 commit comments

Comments
 (0)