Skip to content

Commit 0758a56

Browse files
core: using testing.B.Loop (#32662)
Co-authored-by: lightclient <[email protected]>
1 parent 9b1896b commit 0758a56

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

core/bench_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ func makeChainForBench(db ethdb.Database, genesis *Genesis, full bool, count uin
301301

302302
func benchWriteChain(b *testing.B, full bool, count uint64) {
303303
genesis := &Genesis{Config: params.AllEthashProtocolChanges}
304-
for i := 0; i < b.N; i++ {
304+
for b.Loop() {
305305
pdb, err := pebble.New(b.TempDir(), 1024, 128, "", false)
306306
if err != nil {
307307
b.Fatalf("error opening database: %v", err)
@@ -326,9 +326,7 @@ func benchReadChain(b *testing.B, full bool, count uint64) {
326326
db.Close()
327327
options := DefaultConfig().WithArchive(true)
328328
b.ReportAllocs()
329-
b.ResetTimer()
330-
331-
for i := 0; i < b.N; i++ {
329+
for b.Loop() {
332330
pdb, err = pebble.New(dir, 1024, 128, "", false)
333331
if err != nil {
334332
b.Fatalf("error opening database: %v", err)

core/rlp_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ func BenchmarkHashing(b *testing.B) {
149149
var got common.Hash
150150
var hasher = sha3.NewLegacyKeccak256()
151151
b.Run("iteratorhashing", func(b *testing.B) {
152-
b.ResetTimer()
153-
for i := 0; i < b.N; i++ {
152+
for b.Loop() {
154153
var hash common.Hash
155154
it, err := rlp.NewListIterator(bodyRlp)
156155
if err != nil {
@@ -172,8 +171,7 @@ func BenchmarkHashing(b *testing.B) {
172171
})
173172
var exp common.Hash
174173
b.Run("fullbodyhashing", func(b *testing.B) {
175-
b.ResetTimer()
176-
for i := 0; i < b.N; i++ {
174+
for b.Loop() {
177175
var body types.Body
178176
rlp.DecodeBytes(bodyRlp, &body)
179177
for _, tx := range body.Transactions {
@@ -182,8 +180,7 @@ func BenchmarkHashing(b *testing.B) {
182180
}
183181
})
184182
b.Run("fullblockhashing", func(b *testing.B) {
185-
b.ResetTimer()
186-
for i := 0; i < b.N; i++ {
183+
for b.Loop() {
187184
var block types.Block
188185
rlp.DecodeBytes(blockRlp, &block)
189186
for _, tx := range block.Transactions() {

0 commit comments

Comments
 (0)