Skip to content

Commit 64c6de7

Browse files
authored
p2p: using testing.B.Loop (#32664)
1 parent 1601f39 commit 64c6de7

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

p2p/discover/v5wire/encoding_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,10 +477,9 @@ func BenchmarkV5_DecodeHandshakePingSecp256k1(b *testing.B) {
477477
b.Fatal("can't encode handshake packet")
478478
}
479479
challenge.Node = nil // force ENR signature verification in decoder
480-
b.ResetTimer()
481480

482481
input := make([]byte, len(enc))
483-
for i := 0; i < b.N; i++ {
482+
for b.Loop() {
484483
copy(input, enc)
485484
net.nodeB.c.sc.storeSentHandshake(idA, "", challenge)
486485
_, _, _, err := net.nodeB.c.Decode(input, "")
@@ -507,10 +506,9 @@ func BenchmarkV5_DecodePing(b *testing.B) {
507506
if err != nil {
508507
b.Fatalf("can't encode: %v", err)
509508
}
510-
b.ResetTimer()
511509

512510
input := make([]byte, len(enc))
513-
for i := 0; i < b.N; i++ {
511+
for b.Loop() {
514512
copy(input, enc)
515513
_, _, packet, _ := net.nodeB.c.Decode(input, addrB)
516514
if _, ok := packet.(*Ping); !ok {

p2p/netutil/net_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func TestCheckRelayIP(t *testing.T) {
187187
func BenchmarkCheckRelayIP(b *testing.B) {
188188
sender := parseIP("23.55.1.242")
189189
addr := parseIP("23.55.1.2")
190-
for i := 0; i < b.N; i++ {
190+
for b.Loop() {
191191
CheckRelayIP(sender, addr)
192192
}
193193
}

p2p/rlpx/rlpx_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,7 @@ func TestHandshakeForwardCompatibility(t *testing.T) {
369369

370370
func BenchmarkHandshakeRead(b *testing.B) {
371371
var input = unhex(eip8HandshakeAuthTests[0].input)
372-
373-
for i := 0; i < b.N; i++ {
372+
for b.Loop() {
374373
var (
375374
h handshakeState
376375
r = bytes.NewReader(input)
@@ -427,7 +426,7 @@ func BenchmarkThroughput(b *testing.B) {
427426
// Read N messages.
428427
b.SetBytes(int64(len(msgdata)))
429428
b.ReportAllocs()
430-
for i := 0; i < b.N; i++ {
429+
for b.Loop() {
431430
_, _, _, err := conn2.Read()
432431
if err != nil {
433432
b.Fatal("read error:", err)

0 commit comments

Comments
 (0)