| 115 | } |
| 116 | |
| 117 | func BenchmarkDecompress(b *testing.B) { |
| 118 | data := []byte(strings.Repeat("123456789", 1024)) |
| 119 | |
| 120 | testCases := []struct { |
| 121 | name string |
| 122 | }{ |
| 123 | { |
| 124 | name: snappy.Name, |
| 125 | }, |
| 126 | { |
| 127 | name: snappyblock.Name, |
| 128 | }, |
| 129 | { |
| 130 | name: zstd.Name, |
| 131 | }, |
| 132 | } |
| 133 | |
| 134 | for _, tc := range testCases { |
| 135 | b.Run(tc.name, func(b *testing.B) { |
| 136 | c := encoding.GetCompressor(tc.name) |
| 137 | var buf bytes.Buffer |
| 138 | w, _ := c.Compress(&buf) |
| 139 | _, _ = w.Write(data) |
| 140 | w.Close() |
| 141 | for b.Loop() { |
| 142 | _, _, err := decompress(c, buf.Bytes(), 10000) |
| 143 | require.NoError(b, err) |
| 144 | } |
| 145 | b.ReportAllocs() |
| 146 | }) |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | // This function was copied from: https://github.com/grpc/grpc-go/blob/70c52915099a3b30848d0cb22e2f8951dd5aed7f/rpc_util.go#L765 |
| 151 | func decompress(compressor encoding.Compressor, d []byte, maxReceiveMessageSize int) ([]byte, int, error) { |