Skip to content

Commit e952400

Browse files
committed
benchmarks
1 parent 0e6454f commit e952400

File tree

4 files changed

+50
-15
lines changed

4 files changed

+50
-15
lines changed

ExtendedJavaScriptSubset.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<Solution>
22
<Folder Name="/Benchmarks/">
33
<Project Path="benchmarks\HydraScript.Benchmarks\HydraScript.Benchmarks.csproj" Type="Classic C#" />
4+
<File Path="benchmarks\Readme.md" />
45
</Folder>
56
<Folder Name="/SolutionItems/">
67
<File Path=".gitignore" />
Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,53 @@
11
using BenchmarkDotNet.Attributes;
2-
using BenchmarkDotNet.Jobs;
32
using BenchmarkDotNet.Running;
3+
using HydraScript.Benchmarks;
44
using HydraScript.Infrastructure;
55
using Microsoft.Extensions.DependencyInjection;
66
using Microsoft.Extensions.Logging;
7+
using Microsoft.Extensions.Logging.Abstractions;
8+
using Microsoft.Extensions.Options;
79

810
BenchmarkRunner.Run<InvokeBenchmark>();
911

10-
[MemoryDiagnoser]
11-
[SimpleJob(RuntimeMoniker.NativeAot90)]
12+
[InProcess, MemoryDiagnoser]
1213
public 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
}
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
```
2+
3+
BenchmarkDotNet v0.15.4, Windows 10 (10.0.19045.6332/22H2/2022Update)
4+
12th Gen Intel Core i7-12650H 2.30GHz, 1 CPU, 16 logical and 10 physical cores
5+
.NET SDK 9.0.305
6+
[Host] : .NET 9.0.9 (9.0.9, 9.0.925.41916), X64 RyuJIT x86-64-v3
7+
8+
Job=InProcess Toolchain=InProcessEmitToolchain
9+
10+
```
11+
| Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated |
12+
|--------|---------:|----------:|----------:|---------:|---------:|----------:|
13+
| Invoke | 8.748 ms | 0.1720 ms | 0.2574 ms | 828.1250 | 343.7500 | 10.06 MB |

0 commit comments

Comments
 (0)