File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66
77 <ItemGroup >
88 <PackageReference Include =" Carter" Version =" 10.0.0" />
9- <PackageReference Include =" Utf8Json" Version =" 1.3.7" />
109 </ItemGroup >
1110</Project >
Original file line number Diff line number Diff line change 11using Carter ;
22using Microsoft . AspNetCore . Builder ;
3- using Microsoft . AspNetCore . Http ;
43using Microsoft . AspNetCore . Routing ;
5- using Utf8Json ;
64
75namespace Benchmarks
86{
97 public class JsonModule : ICarterModule
108 {
11- private const int _bufferSize = 27 ;
12-
13- public struct JsonMessage
14- {
15- public string message ;
16- }
17-
189 public void AddRoutes ( IEndpointRouteBuilder app )
1910 {
20- app . MapGet ( "/json" , ( HttpResponse res ) =>
21- {
22- res . StatusCode = 200 ;
23- res . ContentType = "application/json" ;
24- res . ContentLength = _bufferSize ;
25-
26- var msg = new JsonMessage { message = "Hello, World!" } ;
27-
28- return JsonSerializer . SerializeAsync ( res . Body , msg ) ;
29- } ) ;
11+ app . MapGet ( "/json" , ( ) => new { message = "Hello, World!" } ) ;
3012 }
3113 }
3214}
Original file line number Diff line number Diff line change 1- using System . Text ;
2- using Carter ;
1+ using Carter ;
32using Microsoft . AspNetCore . Builder ;
4- using Microsoft . AspNetCore . Http ;
53using Microsoft . AspNetCore . Routing ;
64
75namespace Benchmarks
86{
97 public class PlainModule : ICarterModule
108 {
11- private static readonly byte [ ] _helloWorldPayload = Encoding . UTF8 . GetBytes ( "Hello, World!" ) ;
12-
13-
149 public void AddRoutes ( IEndpointRouteBuilder app )
1510 {
16- app . MapGet ( "/plaintext" , ( HttpResponse res ) =>
17- {
18- var payloadLength = _helloWorldPayload . Length ;
19- res . StatusCode = 200 ;
20- res . ContentType = "text/plain" ;
21- res . ContentLength = payloadLength ;
22- return res . Body . WriteAsync ( _helloWorldPayload , 0 , payloadLength ) ;
23- } ) ;
11+ app . MapGet ( "/plaintext" , ( ) => "Hello, World!" ) ;
2412 }
2513 }
2614}
Original file line number Diff line number Diff line change 11{
22 "framework" : " carter" ,
3+ "maintainers" :[" jchannon" ],
34 "tests" : [{
45 "default" : {
56 "plaintext_url" : " /plaintext" ,
You can’t perform that action at this time.
0 commit comments