mirror of
https://github.com/golang/go
synced 2024-11-17 22:14:43 -07:00
net: add BenchmarkReadWriteMsgUDPAddrPort
The main item of interest here is the allocs. BenchmarkReadWriteMsgUDPAddrPort-8 195920 6450 ns/op 176 B/op 5 allocs/op Change-Id: I358bd18888ce254b6c6d5d5c920e6d22ce5a2ef4 Reviewed-on: https://go-review.googlesource.com/c/go/+/360595 Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
65f3478633
commit
b0472aa990
@ -474,6 +474,27 @@ func TestUDPReadTimeout(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkReadWriteMsgUDPAddrPort(b *testing.B) {
|
||||
conn, err := ListenUDP("udp4", &UDPAddr{IP: IPv4(127, 0, 0, 1)})
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
addr := conn.LocalAddr().(*UDPAddr).AddrPort()
|
||||
buf := make([]byte, 8)
|
||||
b.ResetTimer()
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, _, err := conn.WriteMsgUDPAddrPort(buf, nil, addr)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
_, _, _, _, err = conn.ReadMsgUDPAddrPort(buf, nil)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkWriteToReadFromUDP(b *testing.B) {
|
||||
conn, err := ListenUDP("udp4", &UDPAddr{IP: IPv4(127, 0, 0, 1)})
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user