@@ -12,21 +12,35 @@ public class RequestDelegateGeneratorBenchmarks : RequestDelegateCreationTestBas
1212 [ Params ( 10 , 100 , 1000 , 10000 ) ]
1313 public int EndpointCount { get ; set ; }
1414
15- private string _source ;
15+ private GeneratorDriver _driver ;
16+ private Compilation _compilation ;
1617
1718 [ GlobalSetup ]
18- public void Setup ( )
19+ public async Task Setup ( )
1920 {
20- _source = "" ;
21+ var project = CreateProject ( ) ;
22+ var innerSource = "" ;
2123 for ( var i = 0 ; i < EndpointCount ; i ++ )
2224 {
23- _source += $ """ app.MapGet("/route{ i } ", (int? id) => "Hello World!");""" ;
25+ innerSource += $ """ app.MapGet("/route{ i } ", (int? id) => "Hello World!");""" ;
2426 }
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 ) ;
2538 }
2639
2740 [ Benchmark ]
28- public async Task CreateRequestDelegate ( )
41+ public void CreateRequestDelegate ( )
2942 {
30- await RunGeneratorAsync ( _source ) ;
43+ _driver . RunGeneratorsAndUpdateCompilation ( _compilation , out var _ , out var _ ) ;
3144 }
3245}
46+ }
0 commit comments