5
5
using System . Buffers ;
6
6
using System . IO . Pipelines ;
7
7
using System . Runtime . CompilerServices ;
8
+
8
9
using BenchmarkDotNet . Attributes ;
10
+
9
11
using Microsoft . AspNetCore . Http . Features ;
12
+ using Microsoft . AspNetCore . Http . Features . Authentication ;
10
13
using Microsoft . AspNetCore . Server . Kestrel . Core ;
14
+ using Microsoft . AspNetCore . Server . Kestrel . Core . Features ;
11
15
using Microsoft . AspNetCore . Server . Kestrel . Core . Internal . Http ;
12
16
using Microsoft . AspNetCore . Testing ;
13
17
@@ -17,73 +21,205 @@ public class HttpProtocolFeatureCollection
17
21
{
18
22
private readonly IFeatureCollection _collection ;
19
23
20
- [ Benchmark ]
24
+ [ Benchmark ( Description = "Get<IHttpRequestFeature>*" ) ]
21
25
[ MethodImpl ( MethodImplOptions . NoInlining ) ]
22
- public IHttpRequestFeature GetViaTypeOf_IHttpRequestFeature ( )
26
+ public IHttpRequestFeature Get_IHttpRequestFeature ( )
23
27
{
24
- return ( IHttpRequestFeature ) _collection [ typeof ( IHttpRequestFeature ) ] ;
28
+ return _collection . Get < IHttpRequestFeature > ( ) ;
25
29
}
26
30
27
- [ Benchmark ]
31
+ [ Benchmark ( Description = "Get<IHttpRequestBodyDetectionFeature>*" ) ]
28
32
[ MethodImpl ( MethodImplOptions . NoInlining ) ]
29
- public IHttpRequestFeature GetViaGeneric_IHttpRequestFeature ( )
33
+ public IHttpRequestBodyDetectionFeature Get_IHttpRequestBodyDetectionFeature ( )
30
34
{
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 > ( ) ;
32
106
}
33
107
34
- [ Benchmark ]
108
+ [ Benchmark ( Description = "Get<IHttpRequestTrailersFeature>*" ) ]
35
109
[ MethodImpl ( MethodImplOptions . NoInlining ) ]
36
- public IQueryFeature GetViaTypeOf_IQueryFeature ( )
110
+ public IHttpRequestTrailersFeature Get_IHttpRequestTrailersFeature ( )
37
111
{
38
- return ( IQueryFeature ) _collection [ typeof ( IQueryFeature ) ] ;
112
+ return _collection . Get < IHttpRequestTrailersFeature > ( ) ;
39
113
}
40
114
41
- [ Benchmark ]
115
+ [ Benchmark ( Description = "Get<IQueryFeature>" ) ]
42
116
[ MethodImpl ( MethodImplOptions . NoInlining ) ]
43
- public IQueryFeature GetViaGeneric_IQueryFeature ( )
117
+ public IQueryFeature Get_IQueryFeature ( )
44
118
{
45
119
return _collection . Get < IQueryFeature > ( ) ;
46
120
}
47
121
48
- [ Benchmark ]
122
+ [ Benchmark ( Description = "Get<IFormFeature>" ) ]
49
123
[ MethodImpl ( MethodImplOptions . NoInlining ) ]
50
- public IHttpResetFeature GetViaTypeOf_IHttpResetFeature ( )
124
+ public IFormFeature Get_IFormFeature ( )
51
125
{
52
- return ( IHttpResetFeature ) _collection [ typeof ( IHttpResetFeature ) ] ;
126
+ return _collection . Get < IFormFeature > ( ) ;
53
127
}
54
128
55
- [ Benchmark ]
129
+ [ Benchmark ( Description = "Get<IHttpUpgradeFeature>*" ) ]
56
130
[ MethodImpl ( MethodImplOptions . NoInlining ) ]
57
- public IHttpResetFeature GetViaGeneric_IHttpResetFeature ( )
131
+ public IHttpUpgradeFeature Get_IHttpUpgradeFeature ( )
58
132
{
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 > ( ) ;
60
169
}
61
170
62
- [ Benchmark ]
171
+ [ Benchmark ( Description = "Get<IHttpWebSocketFeature>" ) ]
63
172
[ MethodImpl ( MethodImplOptions . NoInlining ) ]
64
- public object GetViaTypeOf_Custom ( )
173
+ public IHttpWebSocketFeature Get_IHttpWebSocketFeature ( )
65
174
{
66
- return ( IHttpCustomFeature ) _collection [ typeof ( IHttpCustomFeature ) ] ;
175
+ return _collection . Get < IHttpWebSocketFeature > ( ) ;
67
176
}
68
177
69
- [ Benchmark ]
178
+ [ Benchmark ( Description = "Get<ISessionFeature>" ) ]
70
179
[ MethodImpl ( MethodImplOptions . NoInlining ) ]
71
- public object GetViaGeneric_Custom ( )
180
+ public ISessionFeature Get_ISessionFeature ( )
72
181
{
73
- return _collection . Get < IHttpCustomFeature > ( ) ;
182
+ return _collection . Get < ISessionFeature > ( ) ;
74
183
}
75
184
185
+ [ Benchmark ( Description = "Get<IHttpMaxRequestBodySizeFeature>*" ) ]
186
+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
187
+ public IHttpMaxRequestBodySizeFeature Get_IHttpMaxRequestBodySizeFeature ( )
188
+ {
189
+ return _collection . Get < IHttpMaxRequestBodySizeFeature > ( ) ;
190
+ }
76
191
77
- [ Benchmark ]
192
+ [ Benchmark ( Description = "Get<IHttpMinRequestBodyDataRateFeature>*" ) ]
78
193
[ MethodImpl ( MethodImplOptions . NoInlining ) ]
79
- public object GetViaTypeOf_NotFound ( )
194
+ public IHttpMinRequestBodyDataRateFeature Get_IHttpMinRequestBodyDataRateFeature ( )
80
195
{
81
- return ( IHttpNotFoundFeature ) _collection [ typeof ( IHttpNotFoundFeature ) ] ;
196
+ return _collection . Get < IHttpMinRequestBodyDataRateFeature > ( ) ;
82
197
}
83
198
84
- [ Benchmark ]
199
+ [ Benchmark ( Description = "Get<IHttpMinResponseDataRateFeature>*" ) ]
85
200
[ 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 ( )
87
223
{
88
224
return _collection . Get < IHttpNotFoundFeature > ( ) ;
89
225
}
@@ -114,11 +250,7 @@ public HttpProtocolFeatureCollection()
114
250
_collection = http1Connection ;
115
251
}
116
252
117
- private interface IHttpCustomFeature
118
- {
119
- }
120
-
121
- private interface IHttpNotFoundFeature
253
+ public interface IHttpNotFoundFeature
122
254
{
123
255
}
124
256
}
0 commit comments