MCPcopy
hub / github.com/gofiber/fiber / Benchmark_Ctx_Body_With_Compression

Function Benchmark_Ctx_Body_With_Compression

ctx_test.go:1142–1261  ·  view source on GitHub ↗

go test -v -run=^$ -bench=Benchmark_Ctx_Body_With_Compression -benchmem -count=4

(b *testing.B)

Source from the content-addressed store, hash-verified

1140
1141// go test -v -run=^$ -bench=Benchmark_Ctx_Body_With_Compression -benchmem -count=4
1142func Benchmark_Ctx_Body_With_Compression(b *testing.B) {
1143 encodingErr := errors.New("failed to encoding data")
1144
1145 var (
1146 compressGzip = func(data []byte) ([]byte, error) {
1147 var buf bytes.Buffer
1148 writer := gzip.NewWriter(&buf)
1149 if _, err := writer.Write(data); err != nil {
1150 return nil, encodingErr
1151 }
1152 if err := writer.Flush(); err != nil {
1153 return nil, encodingErr
1154 }
1155 if err := writer.Close(); err != nil {
1156 return nil, encodingErr
1157 }
1158 return buf.Bytes(), nil
1159 }
1160 compressDeflate = func(data []byte) ([]byte, error) {
1161 var buf bytes.Buffer
1162 writer := zlib.NewWriter(&buf)
1163 if _, err := writer.Write(data); err != nil {
1164 return nil, encodingErr
1165 }
1166 if err := writer.Flush(); err != nil {
1167 return nil, encodingErr
1168 }
1169 if err := writer.Close(); err != nil {
1170 return nil, encodingErr
1171 }
1172 return buf.Bytes(), nil
1173 }
1174 )
1175 const input = "john=doe"
1176 compressionTests := []struct {
1177 compressWriter func([]byte) ([]byte, error)
1178 contentEncoding string
1179 expectedBody []byte
1180 }{
1181 {
1182 contentEncoding: "gzip",
1183 compressWriter: compressGzip,
1184 expectedBody: []byte(input),
1185 },
1186 {
1187 contentEncoding: "gzip,invalid",
1188 compressWriter: compressGzip,
1189 expectedBody: []byte(ErrUnsupportedMediaType.Error()),
1190 },
1191 {
1192 contentEncoding: StrDeflate,
1193 compressWriter: compressDeflate,
1194 expectedBody: []byte(input),
1195 },
1196 {
1197 contentEncoding: "gzip,deflate",
1198 compressWriter: func(data []byte) ([]byte, error) {
1199 var (

Callers

nothing calls this directly

Calls 13

BytesMethod · 0.95
LenMethod · 0.95
AcquireCtxMethod · 0.80
NewFunction · 0.70
NewMethod · 0.65
WriteMethod · 0.65
CloseMethod · 0.65
ErrorMethod · 0.65
ResetMethod · 0.65
SetMethod · 0.65
RequestMethod · 0.65
BodyMethod · 0.65

Tested by

no test coverage detected