(b *testing.B)
| 101 | } |
| 102 | |
| 103 | func BenchmarkCodeMarshal(b *testing.B) { |
| 104 | b.ReportAllocs() |
| 105 | if codeJSON == nil { |
| 106 | b.StopTimer() |
| 107 | codeInit() |
| 108 | b.StartTimer() |
| 109 | } |
| 110 | b.RunParallel(func(pb *testing.PB) { |
| 111 | for pb.Next() { |
| 112 | if _, err := Marshal(&codeStruct); err != nil { |
| 113 | b.Fatal("Marshal:", err) |
| 114 | } |
| 115 | } |
| 116 | }) |
| 117 | b.SetBytes(int64(len(codeJSON))) |
| 118 | } |
| 119 | |
| 120 | func benchMarshalBytes(n int) func(*testing.B) { |
| 121 | sample := []byte("hello world") |