Skip to content

Commit 5559ae0

Browse files
committed
benchmarks
1 parent 40639a9 commit 5559ae0

File tree

5 files changed

+66
-3
lines changed

5 files changed

+66
-3
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: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<Solution>
2+
<Folder Name="/Benchmarks/">
3+
<Project Path="benchmarks\HydraScript.Benchmarks\HydraScript.Benchmarks.csproj" Type="Classic C#" />
4+
</Folder>
25
<Folder Name="/SolutionItems/">
36
<File Path=".gitignore" />
47
<File Path="CODE_OF_CONDUCT.md" />
@@ -41,10 +44,10 @@
4144
<Project Path="src/Infrastructure/HydraScript.Infrastructure/HydraScript.Infrastructure.csproj" />
4245
</Folder>
4346
<Folder Name="/Tests/">
44-
<File Path="tests/Directory.Build.props" />
45-
<File Path="tests/Directory.Packages.props" />
4647
<Project Path="tests/HydraScript.Infrastructure.LexerRegexGenerator.UnitTests/HydraScript.Infrastructure.LexerRegexGenerator.UnitTests.csproj" />
4748
<Project Path="tests/HydraScript.IntegrationTests/HydraScript.IntegrationTests.csproj" />
4849
<Project Path="tests/HydraScript.UnitTests/HydraScript.UnitTests.csproj" />
50+
<File Path="tests/Directory.Build.props" />
51+
<File Path="tests/Directory.Packages.props" />
4952
</Folder>
50-
</Solution>
53+
</Solution>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
BenchmarkDotNet.Artifacts
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: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using BenchmarkDotNet.Attributes;
2+
using BenchmarkDotNet.Jobs;
3+
using BenchmarkDotNet.Running;
4+
using HydraScript.Infrastructure;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using Microsoft.Extensions.Logging;
7+
8+
BenchmarkRunner.Run<InvokeBenchmark>();
9+
10+
[MemoryDiagnoser]
11+
[SimpleJob(RuntimeMoniker.NativeAot90)]
12+
public class InvokeBenchmark
13+
{
14+
private ServiceProvider? _provider;
15+
private Executor? _executor;
16+
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;
24+
25+
[GlobalSetup]
26+
public void GlobalSetup()
27+
{
28+
var services = new ServiceCollection();
29+
services.AddLogging(c => c.ClearProviders().AddConsole())
30+
.AddDomain()
31+
.AddApplication()
32+
.AddInfrastructure(dump: false, new FileInfo(ScriptPath));
33+
_provider = services.BuildServiceProvider();
34+
_executor = _provider.GetRequiredService<Executor>();
35+
}
36+
37+
[GlobalCleanup]
38+
public void GlobalCleanup() => _provider?.Dispose();
39+
40+
[Benchmark]
41+
public void Invoke() => _executor?.Invoke();
42+
}

0 commit comments

Comments
 (0)