MCPcopy Index your code
hub / github.com/cortexproject/cortex / BenchmarkDecompress

Function BenchmarkDecompress

pkg/util/grpcencoding/encoding_test.go:117–148  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

115}
116
117func 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
151func decompress(compressor encoding.Compressor, d []byte, maxReceiveMessageSize int) ([]byte, int, error) {

Callers

nothing calls this directly

Calls 7

BytesMethod · 0.95
LoopMethod · 0.80
decompressFunction · 0.70
RunMethod · 0.65
CloseMethod · 0.65
CompressMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected