11using BenchmarkDotNet . Attributes ;
2- using BenchmarkDotNet . Jobs ;
32using BenchmarkDotNet . Running ;
3+ using HydraScript . Benchmarks ;
44using HydraScript . Infrastructure ;
55using Microsoft . Extensions . DependencyInjection ;
66using Microsoft . Extensions . Logging ;
7+ using Microsoft . Extensions . Logging . Abstractions ;
8+ using Microsoft . Extensions . Options ;
79
810BenchmarkRunner . Run < InvokeBenchmark > ( ) ;
911
10- [ MemoryDiagnoser ]
11- [ SimpleJob ( RuntimeMoniker . NativeAot90 ) ]
12+ [ InProcess , MemoryDiagnoser ]
1213public class InvokeBenchmark
1314{
1415 private ServiceProvider ? _provider ;
1516 private Executor ? _executor ;
17+ private readonly UpdatableFileOptions _updatableFileOptions = new ( new FileInfo ( nameof ( FileInfo ) ) ) ;
1618
17- private readonly string _samplesPath = Path . Combine (
18- paths : Enumerable . Repeat ( ".." , 6 ) . ToArray ( )
19- . Concat ( [ "hydrascript" , "tests" , "HydraScript.IntegrationTests" , "Samples" ] )
20- . ToArray ( ) ) ;
21- public IEnumerable < string > ScriptPaths => Directory . GetFiles ( _samplesPath ) ;
22- [ ParamsSource ( nameof ( ScriptPaths ) ) ]
23- public required string ScriptPath ;
19+ private readonly IReadOnlyList < FileInfo > _scriptPaths =
20+ Directory . GetFiles (
21+ Path . Combine (
22+ paths : Enumerable . Repeat ( ".." , 6 ) . ToArray ( )
23+ . Concat ( [ "hydrascript" , "tests" , "HydraScript.IntegrationTests" , "Samples" ] )
24+ . ToArray ( ) ) )
25+ . Select ( x => new FileInfo ( x ) )
26+ . ToArray ( ) ;
2427
2528 [ GlobalSetup ]
2629 public void GlobalSetup ( )
2730 {
28- var services = new ServiceCollection ( ) ;
29- services . AddLogging ( c => c . ClearProviders ( ) . AddConsole ( ) )
31+ _provider = new ServiceCollection ( )
32+ . AddLogging ( x => x . ClearProviders ( ) . AddProvider ( NullLoggerProvider . Instance ) )
3033 . AddDomain ( )
3134 . AddApplication ( )
32- . AddInfrastructure ( dump : false , new FileInfo ( ScriptPath ) ) ;
33- _provider = services . BuildServiceProvider ( ) ;
35+ . AddInfrastructure ( dump : false , _updatableFileOptions . Value )
36+ . AddSingleton < IOptions < FileInfo > > ( _updatableFileOptions )
37+ . BuildServiceProvider ( ) ;
3438 _executor = _provider . GetRequiredService < Executor > ( ) ;
3539 }
3640
3741 [ GlobalCleanup ]
3842 public void GlobalCleanup ( ) => _provider ? . Dispose ( ) ;
3943
4044 [ Benchmark ]
41- public void Invoke ( ) => _executor ? . Invoke ( ) ;
45+ public void Invoke ( )
46+ {
47+ for ( var i = 0 ; i < _scriptPaths . Count ; i ++ )
48+ {
49+ _updatableFileOptions . Update ( _scriptPaths [ i ] ) ;
50+ _executor ? . Invoke ( ) ;
51+ }
52+ }
4253}
0 commit comments