(b *testing.B)
| 10 | ) |
| 11 | |
| 12 | func BenchmarkJSON(b *testing.B) { |
| 13 | sizes := []int{ |
| 14 | 8, |
| 15 | 16, |
| 16 | 32, |
| 17 | 128, |
| 18 | 256, |
| 19 | 512, |
| 20 | 1024, |
| 21 | 2048, |
| 22 | 4096, |
| 23 | 8192, |
| 24 | 16384, |
| 25 | } |
| 26 | |
| 27 | b.Run("json.Encoder", func(b *testing.B) { |
| 28 | for _, size := range sizes { |
| 29 | b.Run(strconv.Itoa(size), func(b *testing.B) { |
| 30 | msg := xrand.String(size) |
| 31 | b.SetBytes(int64(size)) |
| 32 | b.ReportAllocs() |
| 33 | b.ResetTimer() |
| 34 | for i := 0; i < b.N; i++ { |
| 35 | json.NewEncoder(io.Discard).Encode(msg) |
| 36 | } |
| 37 | }) |
| 38 | } |
| 39 | }) |
| 40 | b.Run("json.Marshal", func(b *testing.B) { |
| 41 | for _, size := range sizes { |
| 42 | b.Run(strconv.Itoa(size), func(b *testing.B) { |
| 43 | msg := xrand.String(size) |
| 44 | b.SetBytes(int64(size)) |
| 45 | b.ReportAllocs() |
| 46 | b.ResetTimer() |
| 47 | for i := 0; i < b.N; i++ { |
| 48 | json.Marshal(msg) |
| 49 | } |
| 50 | }) |
| 51 | } |
| 52 | }) |
| 53 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…