@@ -12,21 +12,35 @@ public class RequestDelegateGeneratorBenchmarks : RequestDelegateCreationTestBas
12
12
[ Params ( 10 , 100 , 1000 , 10000 ) ]
13
13
public int EndpointCount { get ; set ; }
14
14
15
- private string _source ;
15
+ private GeneratorDriver _driver ;
16
+ private Compilation _compilation ;
16
17
17
18
[ GlobalSetup ]
18
- public void Setup ( )
19
+ public async Task Setup ( )
19
20
{
20
- _source = "" ;
21
+ var project = CreateProject ( ) ;
22
+ var innerSource = "" ;
21
23
for ( var i = 0 ; i < EndpointCount ; i ++ )
22
24
{
23
- _source += $ """ app.MapGet("/route{ i } ", (int? id) => "Hello World!");""" ;
25
+ innerSource += $ """ app.MapGet("/route{ i } ", (int? id) => "Hello World!");""" ;
24
26
}
27
+ var source = GetMapActionString ( innerSource ) ;
28
+ project = project . AddDocument ( "TestMapActions.cs" , SourceText . From ( source , Encoding . UTF8 ) ) . Project ;
29
+ _compilation = await project . GetCompilationAsync ( ) ;
30
+
31
+ var generator = new RequestDelegateGenerator . RequestDelegateGenerator ( ) . AsSourceGenerator ( ) ;
32
+ _driver = CSharpGeneratorDriver . Create ( generators : new [ ]
33
+ {
34
+ generator
35
+ } ,
36
+ driverOptions : new GeneratorDriverOptions ( IncrementalGeneratorOutputKind . None , trackIncrementalGeneratorSteps : true ) ,
37
+ parseOptions : ParseOptions ) ;
25
38
}
26
39
27
40
[ Benchmark ]
28
- public async Task CreateRequestDelegate ( )
41
+ public void CreateRequestDelegate ( )
29
42
{
30
- await RunGeneratorAsync ( _source ) ;
43
+ _driver . RunGeneratorsAndUpdateCompilation ( _compilation , out var _ , out var _ ) ;
31
44
}
32
45
}
46
+ }
0 commit comments