55using System . Buffers ;
66using System . IO . Pipelines ;
77using System . Runtime . CompilerServices ;
8+
89using BenchmarkDotNet . Attributes ;
10+
911using Microsoft . AspNetCore . Http . Features ;
12+ using Microsoft . AspNetCore . Http . Features . Authentication ;
1013using Microsoft . AspNetCore . Server . Kestrel . Core ;
14+ using Microsoft . AspNetCore . Server . Kestrel . Core . Features ;
1115using Microsoft . AspNetCore . Server . Kestrel . Core . Internal . Http ;
1216using Microsoft . AspNetCore . Testing ;
1317
@@ -17,73 +21,205 @@ public class HttpProtocolFeatureCollection
1721 {
1822 private readonly IFeatureCollection _collection ;
1923
20- [ Benchmark ]
24+ [ Benchmark ( Description = "Get<IHttpRequestFeature>*" ) ]
2125 [ MethodImpl ( MethodImplOptions . NoInlining ) ]
22- public IHttpRequestFeature GetViaTypeOf_IHttpRequestFeature ( )
26+ public IHttpRequestFeature Get_IHttpRequestFeature ( )
2327 {
24- return ( IHttpRequestFeature ) _collection [ typeof ( IHttpRequestFeature ) ] ;
28+ return _collection . Get < IHttpRequestFeature > ( ) ;
2529 }
2630
27- [ Benchmark ]
31+ [ Benchmark ( Description = "Get<IHttpRequestBodyDetectionFeature>*" ) ]
2832 [ MethodImpl ( MethodImplOptions . NoInlining ) ]
29- public IHttpRequestFeature GetViaGeneric_IHttpRequestFeature ( )
33+ public IHttpRequestBodyDetectionFeature Get_IHttpRequestBodyDetectionFeature ( )
3034 {
31- return _collection . Get < IHttpRequestFeature > ( ) ;
35+ return _collection . Get < IHttpRequestBodyDetectionFeature > ( ) ;
36+ }
37+
38+ [ Benchmark ( Description = "Get<IHttpResponseFeature>*" ) ]
39+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
40+ public IHttpResponseFeature Get_IHttpResponseFeature ( )
41+ {
42+ return _collection . Get < IHttpResponseFeature > ( ) ;
43+ }
44+
45+ [ Benchmark ( Description = "Get<IHttpResponseBodyFeature>*" ) ]
46+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
47+ public IHttpResponseBodyFeature Get_IHttpResponseBodyFeature ( )
48+ {
49+ return _collection . Get < IHttpResponseBodyFeature > ( ) ;
50+ }
51+
52+ [ Benchmark ( Description = "Get<IRequestBodyPipeFeature>*" ) ]
53+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
54+ public IRequestBodyPipeFeature Get_IRequestBodyPipeFeature ( )
55+ {
56+ return _collection . Get < IRequestBodyPipeFeature > ( ) ;
57+ }
58+
59+ [ Benchmark ( Description = "Get<IHttpRequestIdentifierFeature>*" ) ]
60+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
61+ public IHttpRequestIdentifierFeature Get_IHttpRequestIdentifierFeature ( )
62+ {
63+ return _collection . Get < IHttpRequestIdentifierFeature > ( ) ;
64+ }
65+
66+ [ Benchmark ( Description = "Get<IServiceProvidersFeature>" ) ]
67+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
68+ public IServiceProvidersFeature Get_IServiceProvidersFeature ( )
69+ {
70+ return _collection . Get < IServiceProvidersFeature > ( ) ;
71+ }
72+
73+ [ Benchmark ( Description = "Get<IHttpRequestLifetimeFeature>*" ) ]
74+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
75+ public IHttpRequestLifetimeFeature Get_IHttpRequestLifetimeFeature ( )
76+ {
77+ return _collection . Get < IHttpRequestLifetimeFeature > ( ) ;
78+ }
79+
80+ [ Benchmark ( Description = "Get<IHttpConnectionFeature>*" ) ]
81+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
82+ public IHttpConnectionFeature Get_IHttpConnectionFeature ( )
83+ {
84+ return _collection . Get < IHttpConnectionFeature > ( ) ;
85+ }
86+
87+ [ Benchmark ( Description = "Get<IRouteValuesFeature>*" ) ]
88+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
89+ public IRouteValuesFeature Get_IRouteValuesFeature ( )
90+ {
91+ return _collection . Get < IRouteValuesFeature > ( ) ;
92+ }
93+
94+ [ Benchmark ( Description = "Get<IEndpointFeature>*" ) ]
95+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
96+ public IEndpointFeature Get_IEndpointFeature ( )
97+ {
98+ return _collection . Get < IEndpointFeature > ( ) ;
99+ }
100+
101+ [ Benchmark ( Description = "Get<IHttpAuthenticationFeature>" ) ]
102+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
103+ public IHttpAuthenticationFeature Get_IHttpAuthenticationFeature ( )
104+ {
105+ return _collection . Get < IHttpAuthenticationFeature > ( ) ;
32106 }
33107
34- [ Benchmark ]
108+ [ Benchmark ( Description = "Get<IHttpRequestTrailersFeature>*" ) ]
35109 [ MethodImpl ( MethodImplOptions . NoInlining ) ]
36- public IQueryFeature GetViaTypeOf_IQueryFeature ( )
110+ public IHttpRequestTrailersFeature Get_IHttpRequestTrailersFeature ( )
37111 {
38- return ( IQueryFeature ) _collection [ typeof ( IQueryFeature ) ] ;
112+ return _collection . Get < IHttpRequestTrailersFeature > ( ) ;
39113 }
40114
41- [ Benchmark ]
115+ [ Benchmark ( Description = "Get<IQueryFeature>" ) ]
42116 [ MethodImpl ( MethodImplOptions . NoInlining ) ]
43- public IQueryFeature GetViaGeneric_IQueryFeature ( )
117+ public IQueryFeature Get_IQueryFeature ( )
44118 {
45119 return _collection . Get < IQueryFeature > ( ) ;
46120 }
47121
48- [ Benchmark ]
122+ [ Benchmark ( Description = "Get<IFormFeature>" ) ]
49123 [ MethodImpl ( MethodImplOptions . NoInlining ) ]
50- public IHttpResetFeature GetViaTypeOf_IHttpResetFeature ( )
124+ public IFormFeature Get_IFormFeature ( )
51125 {
52- return ( IHttpResetFeature ) _collection [ typeof ( IHttpResetFeature ) ] ;
126+ return _collection . Get < IFormFeature > ( ) ;
53127 }
54128
55- [ Benchmark ]
129+ [ Benchmark ( Description = "Get<IHttpUpgradeFeature>*" ) ]
56130 [ MethodImpl ( MethodImplOptions . NoInlining ) ]
57- public IHttpResetFeature GetViaGeneric_IHttpResetFeature ( )
131+ public IHttpUpgradeFeature Get_IHttpUpgradeFeature ( )
58132 {
59- return _collection . Get < IHttpResetFeature > ( ) ;
133+ return _collection . Get < IHttpUpgradeFeature > ( ) ;
134+ }
135+
136+ [ Benchmark ( Description = "Get<IHttp2StreamIdFeature>" ) ]
137+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
138+ public IHttp2StreamIdFeature Get_IHttp2StreamIdFeature ( )
139+ {
140+ return _collection . Get < IHttp2StreamIdFeature > ( ) ;
141+ }
142+
143+ [ Benchmark ( Description = "Get<IHttpResponseTrailersFeature>" ) ]
144+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
145+ public IHttpResponseTrailersFeature Get_IHttpResponseTrailersFeature ( )
146+ {
147+ return _collection . Get < IHttpResponseTrailersFeature > ( ) ;
148+ }
149+
150+ [ Benchmark ( Description = "Get<IResponseCookiesFeature>" ) ]
151+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
152+ public IResponseCookiesFeature Get_IResponseCookiesFeature ( )
153+ {
154+ return _collection . Get < IResponseCookiesFeature > ( ) ;
155+ }
156+
157+ [ Benchmark ( Description = "Get<IItemsFeature>" ) ]
158+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
159+ public IItemsFeature Get_IItemsFeature ( )
160+ {
161+ return _collection . Get < IItemsFeature > ( ) ;
162+ }
163+
164+ [ Benchmark ( Description = "Get<ITlsConnectionFeature>" ) ]
165+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
166+ public ITlsConnectionFeature Get_ITlsConnectionFeature ( )
167+ {
168+ return _collection . Get < ITlsConnectionFeature > ( ) ;
60169 }
61170
62- [ Benchmark ]
171+ [ Benchmark ( Description = "Get<IHttpWebSocketFeature>" ) ]
63172 [ MethodImpl ( MethodImplOptions . NoInlining ) ]
64- public object GetViaTypeOf_Custom ( )
173+ public IHttpWebSocketFeature Get_IHttpWebSocketFeature ( )
65174 {
66- return ( IHttpCustomFeature ) _collection [ typeof ( IHttpCustomFeature ) ] ;
175+ return _collection . Get < IHttpWebSocketFeature > ( ) ;
67176 }
68177
69- [ Benchmark ]
178+ [ Benchmark ( Description = "Get<ISessionFeature>" ) ]
70179 [ MethodImpl ( MethodImplOptions . NoInlining ) ]
71- public object GetViaGeneric_Custom ( )
180+ public ISessionFeature Get_ISessionFeature ( )
72181 {
73- return _collection . Get < IHttpCustomFeature > ( ) ;
182+ return _collection . Get < ISessionFeature > ( ) ;
74183 }
75184
185+ [ Benchmark ( Description = "Get<IHttpMaxRequestBodySizeFeature>*" ) ]
186+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
187+ public IHttpMaxRequestBodySizeFeature Get_IHttpMaxRequestBodySizeFeature ( )
188+ {
189+ return _collection . Get < IHttpMaxRequestBodySizeFeature > ( ) ;
190+ }
76191
77- [ Benchmark ]
192+ [ Benchmark ( Description = "Get<IHttpMinRequestBodyDataRateFeature>*" ) ]
78193 [ MethodImpl ( MethodImplOptions . NoInlining ) ]
79- public object GetViaTypeOf_NotFound ( )
194+ public IHttpMinRequestBodyDataRateFeature Get_IHttpMinRequestBodyDataRateFeature ( )
80195 {
81- return ( IHttpNotFoundFeature ) _collection [ typeof ( IHttpNotFoundFeature ) ] ;
196+ return _collection . Get < IHttpMinRequestBodyDataRateFeature > ( ) ;
82197 }
83198
84- [ Benchmark ]
199+ [ Benchmark ( Description = "Get<IHttpMinResponseDataRateFeature>*" ) ]
85200 [ MethodImpl ( MethodImplOptions . NoInlining ) ]
86- public object GetViaGeneric_NotFound ( )
201+ public IHttpMinResponseDataRateFeature Get_IHttpMinResponseDataRateFeature ( )
202+ {
203+ return _collection . Get < IHttpMinResponseDataRateFeature > ( ) ;
204+ }
205+
206+ [ Benchmark ( Description = "Get<IHttpBodyControlFeature>*" ) ]
207+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
208+ public IHttpBodyControlFeature Get_IHttpBodyControlFeature ( )
209+ {
210+ return _collection . Get < IHttpBodyControlFeature > ( ) ;
211+ }
212+
213+ [ Benchmark ( Description = "Get<IHttpResetFeature>" ) ]
214+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
215+ public IHttpResetFeature Get_IHttpResetFeature ( )
216+ {
217+ return _collection . Get < IHttpResetFeature > ( ) ;
218+ }
219+
220+ [ Benchmark ( Description = "Get<IHttpNotFoundFeature>" ) ]
221+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
222+ public IHttpNotFoundFeature Get_IHttpNotFoundFeature ( )
87223 {
88224 return _collection . Get < IHttpNotFoundFeature > ( ) ;
89225 }
@@ -114,11 +250,7 @@ public HttpProtocolFeatureCollection()
114250 _collection = http1Connection ;
115251 }
116252
117- private interface IHttpCustomFeature
118- {
119- }
120-
121- private interface IHttpNotFoundFeature
253+ public interface IHttpNotFoundFeature
122254 {
123255 }
124256 }
0 commit comments