Skip to content

Commit 1a83e39

Browse files
authored
Merge pull request #50266 from dotnet/safia/rdg-benchmarks
Add benchmarks for RDG
2 parents ab38b61 + 96b2556 commit 1a83e39

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.RequestDelegateGenerator.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
<ItemGroup>
1919
<InternalsVisibleTo Include="Microsoft.AspNetCore.Http.Extensions.Tests" />
20+
<InternalsVisibleTo Include="Microsoft.AspNetCore.Http.Microbenchmarks" />
2021
</ItemGroup>
2122

2223
<ItemGroup>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
global using Xunit;

src/Http/Http/perf/Microbenchmarks/Microsoft.AspNetCore.Http.Microbenchmarks.csproj

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,34 @@
66
<ServerGarbageCollection>true</ServerGarbageCollection>
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
88
<RootNamespace>Microsoft.AspNetCore.Http</RootNamespace>
9+
<PreserveCompilationContext>true</PreserveCompilationContext>
910
</PropertyGroup>
1011

1112
<ItemGroup>
1213
<Reference Include="BenchmarkDotNet" />
14+
<Reference Include="Microsoft.AspNetCore" />
15+
<Reference Include="Microsoft.AspNetCore.Testing" />
1316
<Reference Include="Microsoft.AspNetCore.Http" />
17+
<Reference Include="Microsoft.AspNetCore.Http.Results" />
1418
<Reference Include="Microsoft.AspNetCore.Http.Extensions" />
15-
<Compile Include="$(SharedSourceRoot)BenchmarkRunner\*.cs" />
19+
<Reference Include="Microsoft.AspNetCore.Mvc.Core" />
20+
<Reference Include="Microsoft.Extensions.DependencyInjection" />
21+
<Reference Include="Microsoft.Extensions.DependencyModel" />
22+
</ItemGroup>
23+
24+
<ItemGroup>
25+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" IsImplicitlyDefined="true" Version="$(MicrosoftCodeAnalysisVersion_LatestVS)" />
26+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" IsImplicitlyDefined="true" Version="$(MicrosoftCodeAnalysisVersion_LatestVS)" />
27+
</ItemGroup>
28+
29+
<ItemGroup>
30+
<Compile Include="$(RepoRoot)src\Http\Http.Extensions\test\RequestDelegateGenerator\RequestDelegateCreationTestBase.cs" LinkBase="Shared" />
31+
<Compile Include="$(RepoRoot)src\Http\Http.Extensions\test\RequestDelegateGenerator\SharedTypes.cs" LinkBase="Shared" />
32+
<Compile Include="$(SharedSourceRoot)BenchmarkRunner\*.cs" LinkBase="Shared" />
33+
</ItemGroup>
34+
35+
<ItemGroup>
36+
<ProjectReference Include="$(RepoRoot)src\Http\Http.Extensions\gen\Microsoft.AspNetCore.Http.RequestDelegateGenerator.csproj" />
1637
</ItemGroup>
1738

1839
</Project>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
using BenchmarkDotNet.Attributes;
4+
using Microsoft.AspNetCore.Http.Generators.Tests;
5+
6+
namespace Microsoft.AspNetCore.Http.Microbenchmarks;
7+
8+
public class RequestDelegateGeneratorBenchmarks : RequestDelegateCreationTestBase
9+
{
10+
protected override bool IsGeneratorEnabled => true;
11+
12+
[Params(10, 100, 1000, 10000)]
13+
public int EndpointCount { get; set; }
14+
15+
private string _source;
16+
17+
[GlobalSetup]
18+
public void Setup()
19+
{
20+
_source = "";
21+
for (var i = 0; i < EndpointCount; i++)
22+
{
23+
_source += $"""app.MapGet("/route{i}", (int? id) => "Hello World!");""";
24+
}
25+
}
26+
27+
[Benchmark]
28+
public async Task CreateRequestDelegate()
29+
{
30+
await RunGeneratorAsync(_source);
31+
}
32+
}

0 commit comments

Comments
 (0)