core: using testing.B.Loop (#32662)

Co-authored-by: lightclient <lightclient@protonmail.com>
This commit is contained in:
cui 2025-09-20 07:06:27 +08:00 committed by GitHub
parent 9b1896bfb5
commit 0758a561d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 10 deletions

View file

@ -301,7 +301,7 @@ func makeChainForBench(db ethdb.Database, genesis *Genesis, full bool, count uin
func benchWriteChain(b *testing.B, full bool, count uint64) {
genesis := &Genesis{Config: params.AllEthashProtocolChanges}
for i := 0; i < b.N; i++ {
for b.Loop() {
pdb, err := pebble.New(b.TempDir(), 1024, 128, "", false)
if err != nil {
b.Fatalf("error opening database: %v", err)
@ -326,9 +326,7 @@ func benchReadChain(b *testing.B, full bool, count uint64) {
db.Close()
options := DefaultConfig().WithArchive(true)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
pdb, err = pebble.New(dir, 1024, 128, "", false)
if err != nil {
b.Fatalf("error opening database: %v", err)

View file

@ -149,8 +149,7 @@ func BenchmarkHashing(b *testing.B) {
var got common.Hash
var hasher = sha3.NewLegacyKeccak256()
b.Run("iteratorhashing", func(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
var hash common.Hash
it, err := rlp.NewListIterator(bodyRlp)
if err != nil {
@ -172,8 +171,7 @@ func BenchmarkHashing(b *testing.B) {
})
var exp common.Hash
b.Run("fullbodyhashing", func(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
var body types.Body
rlp.DecodeBytes(bodyRlp, &body)
for _, tx := range body.Transactions {
@ -182,8 +180,7 @@ func BenchmarkHashing(b *testing.B) {
}
})
b.Run("fullblockhashing", func(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
var block types.Block
rlp.DecodeBytes(blockRlp, &block)
for _, tx := range block.Transactions() {