func BenchmarkUDP(b *testing.B) {
addr := &net.UDPAddr{IP: net.IP{192, 168, 1, 35}}
var bytesNum int64 = 256
bConn, err := net.ListenUDP("udp", addr)
if err != nil {
b.Fatal(err)
}
bConn.SetWriteBuffer(4096 * 1024)
src := make([]byte, bytesNum)
io.ReadFull(rand.Reader, src)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := bConn.WriteToUDP(src, addr)
if err != nil {
b.Fatal(err)
}
}
b.SetBytes(bytesNum)
}
PASS
BenchmarkUDP-8 500000 8705 ns/op 69.08 MB/s
So average speed is 3705ns for packet of 256 bytes(+ip header), Can I speed up(for given size)?
Or maybe there is a way to use different independent net.UDPConn instances for every client?
So average speed is *8705ns
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
flat flat% sum% cum cum%
7.46days 100% 100% 7.46days 100% runtime.selectgo
BenchmarkListen-4 200000 9631 ns/op 3.32 MB/s
BenchmarkListenSock-4 200000 6264 ns/op 5.11 MB/s
BenchmarkDial-4 200000 6327 ns/op 5.06 MB/s
BenchmarkDialSock-4 200000 6340 ns/op 5.05 MB/s
Looks like WriteToUDP() is the slowest one, these are really good news. Also using net.Conn's Write() method and os.File's Write() are almost the same (in the first just added checking if connection and file descriptor !=nil).