8 "github.com/anacrolix/dht/v2/krpc"
10 "github.com/anacrolix/torrent/bencode"
13 func marshalAndUnmarshal(tb testing.TB, orig krpc.Msg) (ret krpc.Msg) {
14 b, err := bencode.Marshal(orig)
18 err = bencode.Unmarshal(b, &ret)
26 func BenchmarkMarshalThenUnmarshalKrpcMsg(tb *testing.B) {
31 Token: func() *string { t := "re-up"; return &t }(),
33 IP: krpc.NodeAddr{IP: net.ParseIP("1.2.3.4"), Port: 1337},
36 first := marshalAndUnmarshal(tb, orig)
37 if !reflect.DeepEqual(orig, first) {
42 for i := 0; i < tb.N; i += 1 {
43 marshalAndUnmarshal(tb, orig)