File tree Expand file tree Collapse file tree
frameworks/CSharp/carter/Benchmarks Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11<Project Sdk =" Microsoft.NET.Sdk.Web" >
22 <PropertyGroup >
3- <TargetFramework >net5 .0</TargetFramework >
3+ <TargetFramework >net10 .0</TargetFramework >
44 <NoDefaultLaunchSettingsFile >true</NoDefaultLaunchSettingsFile >
55 </PropertyGroup >
66
77 <ItemGroup >
8- <PackageReference Include =" Carter" Version =" 5.2 .0" />
8+ <PackageReference Include =" Carter" Version =" 10.0 .0" />
99 <PackageReference Include =" Utf8Json" Version =" 1.3.7" />
1010 </ItemGroup >
1111</Project >
Original file line number Diff line number Diff line change 1- namespace Benchmarks
2- {
3- using Carter ;
4- using System . Threading . Tasks ;
5- using Utf8Json ;
1+ using Carter ;
2+ using Microsoft . AspNetCore . Builder ;
3+ using Microsoft . AspNetCore . Http ;
4+ using Microsoft . AspNetCore . Routing ;
5+ using Utf8Json ;
66
7- public class JsonModule : CarterModule
7+ namespace Benchmarks
8+ {
9+ public class JsonModule : ICarterModule
810 {
911 private const int _bufferSize = 27 ;
1012
11- public JsonModule ( ) : base ( "json" )
13+ public struct JsonMessage
14+ {
15+ public string message ;
16+ }
17+
18+ public void AddRoutes ( IEndpointRouteBuilder app )
1219 {
13- Get ( "/" , ( req , res ) =>
20+ app . MapGet ( "/json " , ( HttpResponse res ) =>
1421 {
1522 res . StatusCode = 200 ;
1623 res . ContentType = "application/json" ;
@@ -21,10 +28,5 @@ public JsonModule() : base("json")
2128 return JsonSerializer . SerializeAsync ( res . Body , msg ) ;
2229 } ) ;
2330 }
24-
25- public struct JsonMessage
26- {
27- public string message ;
28- }
2931 }
30- }
32+ }
Original file line number Diff line number Diff line change 1- namespace Benchmarks
2- {
3- using Carter ;
4- using System . Text ;
1+ using System . Text ;
2+ using Carter ;
3+ using Microsoft . AspNetCore . Builder ;
4+ using Microsoft . AspNetCore . Http ;
5+ using Microsoft . AspNetCore . Routing ;
56
6- public class PlainModule : CarterModule
7+ namespace Benchmarks
8+ {
9+ public class PlainModule : ICarterModule
710 {
811 private static readonly byte [ ] _helloWorldPayload = Encoding . UTF8 . GetBytes ( "Hello, World!" ) ;
912
10- public PlainModule ( ) : base ( "plaintext" )
13+
14+ public void AddRoutes ( IEndpointRouteBuilder app )
1115 {
12- Get ( "/" , ( req , res ) =>
16+ app . MapGet ( "/plaintext " , ( HttpResponse res ) =>
1317 {
1418 var payloadLength = _helloWorldPayload . Length ;
1519 res . StatusCode = 200 ;
@@ -19,4 +23,4 @@ public PlainModule() : base("plaintext")
1923 } ) ;
2024 }
2125 }
22- }
26+ }
Original file line number Diff line number Diff line change 1- namespace Benchmarks
2- {
3- using System . IO ;
4- using System . Threading . Tasks ;
5- using Microsoft . AspNetCore . Hosting ;
6- using Microsoft . Extensions . Configuration ;
1+ using Carter ;
2+ using Microsoft . AspNetCore . Builder ;
3+ using Microsoft . Extensions . Logging ;
74
8- public class Program
9- {
10- public static async Task Main ( string [ ] args )
11- {
12- var config = new ConfigurationBuilder ( )
13- . AddEnvironmentVariables ( prefix : "ASPNETCORE_" )
14- . AddCommandLine ( args )
15- . Build ( ) ;
5+ var builder = WebApplication . CreateBuilder ( args ) ;
166
17- var webHost = new WebHostBuilder ( )
18- . UseContentRoot ( Directory . GetCurrentDirectory ( ) )
19- . UseConfiguration ( config )
20- . UseStartup < Startup > ( )
21- . UseKestrel ( )
22- . Build ( ) ;
7+ // Disable logging as this is not required for the benchmark
8+ builder . Logging . ClearProviders ( ) ;
9+ builder . Services . AddCarter ( ) ;
10+ var app = builder . Build ( ) ;
2311
24- await webHost . RunAsync ( ) ;
25- }
26- }
27- }
12+ app . MapCarter ( ) ;
13+ app . Run ( ) ;
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments