Skip to content

Commit 1e61d65

Browse files
authored
make benchmarks compilable (#184) +semver:skip
1 parent d2d7311 commit 1e61d65

File tree

14 files changed

+48
-32
lines changed

14 files changed

+48
-32
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Text.RegularExpressions;
2+
using HydraScript.Domain.FrontEnd.Lexer;
3+
using HydraScript.Infrastructure;
4+
5+
namespace HydraScript.Benchmarks;
6+
7+
internal sealed partial class GeneratedRegexContainer : IGeneratedRegexContainer
8+
{
9+
[GeneratedRegex(PatternContainer.Value, RegexOptions.Compiled)]
10+
public static partial Regex Regex { get; }
11+
}

benchmarks/HydraScript.Benchmarks/HydraScript.Benchmarks.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8+
<ProjectReference Include="..\..\src\Domain\HydraScript.Domain.Constants\HydraScript.Domain.Constants.csproj"
9+
OutputItemType="Analyzer" SetTargetFramework="TargetFramework=netstandard2.0"/>
10+
<ProjectReference Include="..\..\src\Infrastructure\HydraScript.Infrastructure.LexerRegexGenerator\HydraScript.Infrastructure.LexerRegexGenerator.csproj"
11+
OutputItemType="Analyzer"
12+
ReferenceOutputAssembly="false"
13+
SetTargetFramework="TargetFramework=netstandard2.0"/>
814
<ProjectReference Include="..\..\src\Infrastructure\HydraScript.Infrastructure\HydraScript.Infrastructure.csproj"/>
915
</ItemGroup>
1016

@@ -13,4 +19,10 @@
1319
<PackageReference Include="Microsoft.Extensions.Logging"/>
1420
</ItemGroup>
1521

22+
<ItemGroup>
23+
<None Include="..\..\tests\HydraScript.IntegrationTests\Samples\**" Link="Samples\%(RecursiveDir)%(FileName)%(Extension)">
24+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
25+
</None>
26+
</ItemGroup>
27+
1628
</Project>

benchmarks/HydraScript.Benchmarks/InvokeBenchmark.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Diagnostics.CodeAnalysis;
22
using BenchmarkDotNet.Attributes;
3+
using BenchmarkDotNet.Jobs;
34
using BenchmarkDotNet.Running;
45
using HydraScript.Benchmarks;
56
using HydraScript.Infrastructure;
@@ -12,19 +13,15 @@
1213

1314
BenchmarkRunner.Run<InvokeBenchmark>();
1415

15-
[InProcess, MemoryDiagnoser]
16+
[SimpleJob(RuntimeMoniker.Net90), MemoryDiagnoser]
1617
public class InvokeBenchmark
1718
{
1819
private ServiceProvider? _provider;
1920
private Executor? _executor;
2021
private readonly UpdatableFileOptions _updatableFileOptions = new(new FileInfo(nameof(FileInfo)));
2122

2223
private readonly IReadOnlyList<FileInfo> _scriptPaths =
23-
Directory.GetFiles(
24-
Path.Combine(
25-
paths: Enumerable.Repeat("..", 6).ToArray()
26-
.Concat(["hydrascript", "tests", "HydraScript.IntegrationTests", "Samples"])
27-
.ToArray()))
24+
Directory.GetFiles("Samples")
2825
.Select(x => new FileInfo(x))
2926
.ToArray();
3027

@@ -33,7 +30,7 @@ public void GlobalSetup()
3330
{
3431
_provider = new ServiceCollection()
3532
.AddLogging(x => x.ClearProviders().AddProvider(NullLoggerProvider.Instance))
36-
.AddDomain()
33+
.AddDomain<GeneratedRegexContainer>()
3734
.AddApplication()
3835
.AddInfrastructure(dump: false, _updatableFileOptions.Value)
3936
.AddSingleton<IOptions<FileInfo>>(_updatableFileOptions)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Text.RegularExpressions;
2+
using HydraScript.Domain.FrontEnd.Lexer;
3+
using HydraScript.Infrastructure;
4+
5+
namespace HydraScript;
6+
7+
public sealed partial class GeneratedRegexContainer : IGeneratedRegexContainer
8+
{
9+
[GeneratedRegex(PatternContainer.Value, RegexOptions.Compiled)]
10+
public static partial Regex Regex { get; }
11+
}

src/HydraScript/HydraScript.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
</PropertyGroup>
1515

1616
<ItemGroup>
17+
<ProjectReference Include="..\Infrastructure\HydraScript.Infrastructure.LexerRegexGenerator\HydraScript.Infrastructure.LexerRegexGenerator.csproj"
18+
OutputItemType="Analyzer"
19+
ReferenceOutputAssembly="false"
20+
PrivateAssets="all" />
1721
<ProjectReference Include="..\Infrastructure\HydraScript.Infrastructure\HydraScript.Infrastructure.csproj" />
1822
</ItemGroup>
1923

src/HydraScript/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private static ExecuteCommand GetCommand()
2828
private static ServiceProvider GetServiceProvider(FileInfo fileInfo, bool dump) =>
2929
new ServiceCollection()
3030
.AddLogging(c => c.ClearProviders().AddZLoggerConsole())
31-
.AddDomain()
31+
.AddDomain<GeneratedRegexContainer>()
3232
.AddApplication()
3333
.AddInfrastructure(dump, fileInfo)
3434
.BuildServiceProvider();

src/Infrastructure/HydraScript.Infrastructure/GeneratedRegexContainer.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/Infrastructure/HydraScript.Infrastructure/HydraScript.Infrastructure.csproj

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@
55
<ProjectReference Include="..\..\Application\HydraScript.Application.StaticAnalysis\HydraScript.Application.StaticAnalysis.csproj" />
66
</ItemGroup>
77

8-
<ItemGroup>
9-
<ProjectReference Include="..\HydraScript.Infrastructure.LexerRegexGenerator\HydraScript.Infrastructure.LexerRegexGenerator.csproj"
10-
OutputItemType="Analyzer"
11-
ReferenceOutputAssembly="false"
12-
PrivateAssets="all"/>
13-
</ItemGroup>
14-
158
<ItemGroup>
169
<PackageReference Include="Microsoft.Extensions.Logging" />
1710
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />

src/Infrastructure/HydraScript.Infrastructure/ServiceCollectionExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ namespace HydraScript.Infrastructure;
1515

1616
public static class ServiceCollectionExtensions
1717
{
18-
public static IServiceCollection AddDomain(this IServiceCollection services)
18+
public static IServiceCollection AddDomain<TGeneratedRegexContainer>(this IServiceCollection services)
19+
where TGeneratedRegexContainer : class, IGeneratedRegexContainer
1920
{
2021
services.AddSingleton<ITextCoordinateSystemComputer, TextCoordinateSystemComputer>();
2122
services.AddSingleton<ITokenTypesProvider, TokenTypesProvider>();
22-
services.AddSingleton<IStructure, Structure<GeneratedRegexContainer>>();
23+
services.AddSingleton<IStructure, Structure<TGeneratedRegexContainer>>();
2324
services.AddSingleton<ILexer, RegexLexer>();
2425
services.AddSingleton<IParser, TopDownParser>();
2526

tests/HydraScript.IntegrationTests/TestHostFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void Dispose()
3434
public Runner GetRunner(Options options, Action<IServiceCollection>? configureTestServices = null)
3535
{
3636
var services = new ServiceCollection()
37-
.AddDomain()
37+
.AddDomain<GeneratedRegexContainer>()
3838
.AddApplication()
3939
.AddInfrastructure(options.Dump, new FileInfo(options.FileName));
4040
const string serilogTemplate = "[{Timestamp:HH:mm:ss} {Level:u} [{SourceContext}]]{NewLine}{Message:lj} {Exception}";

0 commit comments

Comments
 (0)