Skip to content

Commit 2f4a668

Browse files
authored
Benchmarks +semver:skip (#180)
* samples -> Samples * fix HydraScript.csproj * benchmarks * remove partial from PatternContainer * clear state * remove InputFile.cs * benchmarks * fix
1 parent dc6a3a0 commit 2f4a668

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+156
-28
lines changed

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<Project>
22
<ItemGroup>
3+
<PackageVersion Include="BenchmarkDotNet" Version="0.15.4" />
34
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0">
45
<PrivateAssets>all</PrivateAssets>
56
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

ExtendedJavaScriptSubset.slnx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<Solution>
2+
<Folder Name="/Benchmarks/">
3+
<Project Path="benchmarks\HydraScript.Benchmarks\HydraScript.Benchmarks.csproj" Type="Classic C#" />
4+
<File Path="benchmarks\Readme.md" />
5+
</Folder>
26
<Folder Name="/SolutionItems/">
37
<File Path=".gitignore" />
48
<File Path="CODE_OF_CONDUCT.md" />
@@ -41,10 +45,10 @@
4145
<Project Path="src/Infrastructure/HydraScript.Infrastructure/HydraScript.Infrastructure.csproj" />
4246
</Folder>
4347
<Folder Name="/Tests/">
44-
<File Path="tests/Directory.Build.props" />
45-
<File Path="tests/Directory.Packages.props" />
4648
<Project Path="tests/HydraScript.Infrastructure.LexerRegexGenerator.UnitTests/HydraScript.Infrastructure.LexerRegexGenerator.UnitTests.csproj" />
4749
<Project Path="tests/HydraScript.IntegrationTests/HydraScript.IntegrationTests.csproj" />
4850
<Project Path="tests/HydraScript.UnitTests/HydraScript.UnitTests.csproj" />
51+
<File Path="tests/Directory.Build.props" />
52+
<File Path="tests/Directory.Packages.props" />
4953
</Folder>
50-
</Solution>
54+
</Solution>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<ProjectReference Include="..\..\src\Infrastructure\HydraScript.Infrastructure\HydraScript.Infrastructure.csproj"/>
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="BenchmarkDotNet"/>
13+
<PackageReference Include="Microsoft.Extensions.Logging.Console"/>
14+
</ItemGroup>
15+
16+
</Project>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using BenchmarkDotNet.Attributes;
2+
using BenchmarkDotNet.Running;
3+
using HydraScript.Benchmarks;
4+
using HydraScript.Infrastructure;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using Microsoft.Extensions.Logging;
7+
using Microsoft.Extensions.Logging.Abstractions;
8+
using Microsoft.Extensions.Options;
9+
10+
BenchmarkRunner.Run<InvokeBenchmark>();
11+
12+
[InProcess, MemoryDiagnoser]
13+
public class InvokeBenchmark
14+
{
15+
private ServiceProvider? _provider;
16+
private Executor? _executor;
17+
private readonly UpdatableFileOptions _updatableFileOptions = new(new FileInfo(nameof(FileInfo)));
18+
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();
27+
28+
[GlobalSetup]
29+
public void GlobalSetup()
30+
{
31+
_provider = new ServiceCollection()
32+
.AddLogging(x => x.ClearProviders().AddProvider(NullLoggerProvider.Instance))
33+
.AddDomain()
34+
.AddApplication()
35+
.AddInfrastructure(dump: false, _updatableFileOptions.Value)
36+
.AddSingleton<IOptions<FileInfo>>(_updatableFileOptions)
37+
.BuildServiceProvider();
38+
_executor = _provider.GetRequiredService<Executor>();
39+
}
40+
41+
[GlobalCleanup]
42+
public void GlobalCleanup() => _provider?.Dispose();
43+
44+
[Benchmark]
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+
}
53+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Microsoft.Extensions.Options;
2+
3+
namespace HydraScript.Benchmarks;
4+
5+
internal sealed class UpdatableFileOptions(FileInfo fileInfo) : IOptions<FileInfo>
6+
{
7+
public FileInfo Value { get; private set; } = fileInfo;
8+
9+
public void Update(FileInfo fileInfo) => Value = fileInfo;
10+
}

benchmarks/Readme.md

Lines changed: 13 additions & 0 deletions

src/Application/HydraScript.Application.StaticAnalysis/IAmbiguousInvocationStorage.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ public interface IAmbiguousInvocationStorage
99
void CheckCandidatesAndThrow(string segment, FunctionSymbolId invocation);
1010

1111
void Clear(FunctionSymbolId invocation);
12+
13+
void Clear();
1214
}

src/Application/HydraScript.Application.StaticAnalysis/IComputedTypesStorage.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ public interface IComputedTypesStorage
55
public Guid Save(Type computedType);
66

77
public Type Get(Guid computedTypeGuid);
8+
9+
public void Clear();
810
}

src/Application/HydraScript.Application.StaticAnalysis/IMethodStorage.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ public interface IMethodStorage
99
public void BindMethod(ObjectType objectType, FunctionSymbol method);
1010

1111
public IReadOnlyDictionary<FunctionSymbolId, FunctionSymbol> GetAvailableMethods(ObjectType objectType);
12+
13+
public void Clear();
1214
}

src/Application/HydraScript.Application.StaticAnalysis/ISymbolTableStorage.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ public interface ISymbolTableStorage
1010
public void Init(Scope scope, ISymbolTable symbolTable);
1111

1212
public void InitWithOpenScope(Scope scope);
13+
14+
public void Clear();
1315
}

0 commit comments

Comments
 (0)