benchmark encoding a small, "fast" type. the point here is to see how much garbage is generated intrinsically by the encoding/ decoding process as opposed to the nature of the struct.
(b *testing.B)
| 15 | // decoding process as opposed to the nature |
| 16 | // of the struct. |
| 17 | func BenchmarkFastEncode(b *testing.B) { |
| 18 | v := &TestFast{ |
| 19 | Lat: 40.12398, |
| 20 | Long: -41.9082, |
| 21 | Alt: 201.08290, |
| 22 | Data: []byte("whaaaaargharbl"), |
| 23 | } |
| 24 | var buf bytes.Buffer |
| 25 | msgp.Encode(&buf, v) |
| 26 | en := msgp.NewWriter(msgp.Nowhere) |
| 27 | b.SetBytes(int64(buf.Len())) |
| 28 | b.ReportAllocs() |
| 29 | b.ResetTimer() |
| 30 | for i := 0; i < b.N; i++ { |
| 31 | v.EncodeMsg(en) |
| 32 | } |
| 33 | en.Flush() |
| 34 | } |
| 35 | |
| 36 | // benchmark decoding a small, "fast" type. |
| 37 | // the point here is to see how much garbage |