github.com/yandex/pandora@v0.5.32/components/providers/http/decoders/raw/decoder_bench_test.go (about) 1 package raw 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 "github.com/yandex/pandora/components/providers/http/util" 8 ) 9 10 var ( 11 benchTestConfigHeaders = []string{ 12 "[Host: yourhost.tld]", 13 "[Sometest: someval]", 14 } 15 benchTestRequest = []byte("GET / HTTP/1.1\r\n" + 16 "Host: yourhost.tld" + 17 "Content-Length: 0\r\n" + 18 "\r\n") 19 ) 20 21 // $ go test -bench . -benchmem -benchtime=10s 22 // cpu: Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz 23 // BenchmarkRawDecoder-12 9371816 1426 ns/op 5122 B/op 10 allocs/op 24 // BenchmarkRawDecoderWithHeaders-12 6145189 1886 ns/op 5122 B/op 10 allocs/op 25 26 func BenchmarkRawDecoder(b *testing.B) { 27 for i := 0; i < b.N; i++ { 28 _, _ = DecodeRequest(benchTestRequest) 29 } 30 } 31 32 func BenchmarkRawDecoderWithHeaders(b *testing.B) { 33 decodedHTTPConfigHeaders, err := util.DecodeHTTPConfigHeaders(benchTestConfigHeaders) 34 require.NoError(b, err) 35 b.ResetTimer() 36 for i := 0; i < b.N; i++ { 37 req, _ := DecodeRequest(benchTestRequest) 38 util.EnrichRequestWithHeaders(req, decodedHTTPConfigHeaders) 39 } 40 }