triedb: using testing.B.Loop

Signed-off-by: yajianggroup <yajianggroup@outlook.com>
This commit is contained in:
yajianggroup 2025-09-23 15:35:17 +08:00
parent 2872242045
commit a5039f98b9
3 changed files with 13 additions and 17 deletions

View file

@ -83,13 +83,12 @@ func benchmarkSearch(b *testing.B, depth int, total int) {
for i := 0; i < total; i++ {
layer = fill(layer, i)
}
b.ResetTimer()
var (
have []byte
err error
)
for i := 0; i < b.N; i++ {
for b.Loop() {
have, _, _, err = layer.node(common.Hash{}, npath, 0)
if err != nil {
b.Fatal(err)
@ -120,7 +119,7 @@ func BenchmarkPersist(b *testing.B) {
}
return newDiffLayer(parent, common.Hash{}, 0, 0, NewNodeSetWithOrigin(nodes, nil), NewStateSetWithOrigin(nil, nil, nil, nil, false))
}
for i := 0; i < b.N; i++ {
for b.Loop() {
b.StopTimer()
var layer layer
layer = emptyLayer()
@ -163,9 +162,8 @@ func BenchmarkJournal(b *testing.B) {
for i := 0; i < 128; i++ {
layer = fill(layer)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
layer.journal(new(bytes.Buffer))
}
}

View file

@ -224,8 +224,7 @@ func BenchmarkParseIndexBlock(b *testing.B) {
}
blob := bw.finish()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_, _, err := parseIndexBlock(blob)
if err != nil {
b.Fatalf("parseIndexBlock failed: %v", err)
@ -236,12 +235,11 @@ func BenchmarkParseIndexBlock(b *testing.B) {
// BenchmarkBlockWriterAppend benchmarks the performance of indexblock.writer
func BenchmarkBlockWriterAppend(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
desc := newIndexBlockDesc(0)
writer, _ := newBlockWriter(nil, desc)
for i := 0; i < b.N; i++ {
for b.Loop() {
if writer.full() {
desc = newIndexBlockDesc(0)
writer, _ = newBlockWriter(nil, desc)

View file

@ -1051,7 +1051,7 @@ func BenchmarkAccountIteratorTraversal(b *testing.B) {
head.(*diffLayer).newBinaryAccountIterator(common.Hash{})
b.Run("binary iterator keys", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
got := 0
it := head.(*diffLayer).newBinaryAccountIterator(common.Hash{})
for it.Next() {
@ -1063,7 +1063,7 @@ func BenchmarkAccountIteratorTraversal(b *testing.B) {
}
})
b.Run("binary iterator values", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
got := 0
it := head.(*diffLayer).newBinaryAccountIterator(common.Hash{})
for it.Next() {
@ -1076,7 +1076,7 @@ func BenchmarkAccountIteratorTraversal(b *testing.B) {
}
})
b.Run("fast iterator keys", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
it, _ := db.AccountIterator(common.HexToHash("0x65"), common.Hash{})
defer it.Release()
@ -1090,7 +1090,7 @@ func BenchmarkAccountIteratorTraversal(b *testing.B) {
}
})
b.Run("fast iterator values", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
it, _ := db.AccountIterator(common.HexToHash("0x65"), common.Hash{})
defer it.Release()
@ -1142,7 +1142,7 @@ func BenchmarkAccountIteratorLargeBaselayer(b *testing.B) {
head.(*diffLayer).newBinaryAccountIterator(common.Hash{})
b.Run("binary iterator (keys)", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
got := 0
it := head.(*diffLayer).newBinaryAccountIterator(common.Hash{})
for it.Next() {
@ -1154,7 +1154,7 @@ func BenchmarkAccountIteratorLargeBaselayer(b *testing.B) {
}
})
b.Run("binary iterator (values)", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
got := 0
it := head.(*diffLayer).newBinaryAccountIterator(common.Hash{})
for it.Next() {
@ -1168,7 +1168,7 @@ func BenchmarkAccountIteratorLargeBaselayer(b *testing.B) {
}
})
b.Run("fast iterator (keys)", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
it, _ := db.AccountIterator(common.HexToHash("0x65"), common.Hash{})
defer it.Release()
@ -1182,7 +1182,7 @@ func BenchmarkAccountIteratorLargeBaselayer(b *testing.B) {
}
})
b.Run("fast iterator (values)", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
it, _ := db.AccountIterator(common.HexToHash("0x65"), common.Hash{})
defer it.Release()