From 64c6de7747072e72a6df73228c51f751e143ab0c Mon Sep 17 00:00:00 2001 From: cui Date: Sat, 20 Sep 2025 06:38:36 +0800 Subject: [PATCH] p2p: using testing.B.Loop (#32664) --- p2p/discover/v5wire/encoding_test.go | 6 ++---- p2p/netutil/net_test.go | 2 +- p2p/rlpx/rlpx_test.go | 5 ++--- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/p2p/discover/v5wire/encoding_test.go b/p2p/discover/v5wire/encoding_test.go index 2304d0f132..5774cb3d8c 100644 --- a/p2p/discover/v5wire/encoding_test.go +++ b/p2p/discover/v5wire/encoding_test.go @@ -477,10 +477,9 @@ func BenchmarkV5_DecodeHandshakePingSecp256k1(b *testing.B) { b.Fatal("can't encode handshake packet") } challenge.Node = nil // force ENR signature verification in decoder - b.ResetTimer() input := make([]byte, len(enc)) - for i := 0; i < b.N; i++ { + for b.Loop() { copy(input, enc) net.nodeB.c.sc.storeSentHandshake(idA, "", challenge) _, _, _, err := net.nodeB.c.Decode(input, "") @@ -507,10 +506,9 @@ func BenchmarkV5_DecodePing(b *testing.B) { if err != nil { b.Fatalf("can't encode: %v", err) } - b.ResetTimer() input := make([]byte, len(enc)) - for i := 0; i < b.N; i++ { + for b.Loop() { copy(input, enc) _, _, packet, _ := net.nodeB.c.Decode(input, addrB) if _, ok := packet.(*Ping); !ok { diff --git a/p2p/netutil/net_test.go b/p2p/netutil/net_test.go index 569c7ac454..8c810f494f 100644 --- a/p2p/netutil/net_test.go +++ b/p2p/netutil/net_test.go @@ -187,7 +187,7 @@ func TestCheckRelayIP(t *testing.T) { func BenchmarkCheckRelayIP(b *testing.B) { sender := parseIP("23.55.1.242") addr := parseIP("23.55.1.2") - for i := 0; i < b.N; i++ { + for b.Loop() { CheckRelayIP(sender, addr) } } diff --git a/p2p/rlpx/rlpx_test.go b/p2p/rlpx/rlpx_test.go index 27d51546e7..a02c1dc2cc 100644 --- a/p2p/rlpx/rlpx_test.go +++ b/p2p/rlpx/rlpx_test.go @@ -369,8 +369,7 @@ func TestHandshakeForwardCompatibility(t *testing.T) { func BenchmarkHandshakeRead(b *testing.B) { var input = unhex(eip8HandshakeAuthTests[0].input) - - for i := 0; i < b.N; i++ { + for b.Loop() { var ( h handshakeState r = bytes.NewReader(input) @@ -427,7 +426,7 @@ func BenchmarkThroughput(b *testing.B) { // Read N messages. b.SetBytes(int64(len(msgdata))) b.ReportAllocs() - for i := 0; i < b.N; i++ { + for b.Loop() { _, _, _, err := conn2.Read() if err != nil { b.Fatal("read error:", err)