-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: Continuous benchmarking | ||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
push: | ||
branches: | ||
- master | ||
|
||
permissions: | ||
contents: write | ||
deployments: write | ||
|
||
jobs: | ||
benchmark: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup .NET SDK | ||
uses: actions/setup-dotnet@v4 | ||
with: | ||
dotnet-version: 8.0.x | ||
|
||
- name: Run benchmarks | ||
working-directory: src/Benchmarks | ||
run: dotnet run -c Release --exporters json --filter '*' | ||
|
||
- name: Combine benchmarks results | ||
working-directory: src/Benchmarks | ||
run: dotnet tool install -g dotnet-script && dotnet script combine-bechmarks.csx | ||
|
||
- name: Store benchmarks results | ||
uses: benchmark-action/github-action-benchmark@v1 | ||
with: | ||
name: SteroidsDI Benchmarks | ||
tool: 'benchmarkdotnet' | ||
output-file-path: src/Benchmarks/BenchmarkDotNet.Artifacts/results/Combined.Benchmarks.json | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
alert-threshold: '101%' | ||
comment-on-alert: true | ||
fail-on-alert: true | ||
- name: Push benchmarks results | ||
if: github.event_name != 'pull_request' | ||
run: git push 'https://sungam3r:${{ secrets.GITHUB_TOKEN }}@github.com/sungam3r/SteroidsDI.git' gh-pages:gh-pages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<NoWarn>$(NoWarn);1591</NoWarn> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\SteroidsDI.AspNetCore\SteroidsDI.AspNetCore.csproj" /> | ||
<ProjectReference Include="..\SteroidsDI\SteroidsDI.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using SteroidsDI; | ||
|
||
namespace Benchmarks; | ||
|
||
public class DeferBenchmarks | ||
{ | ||
private sealed class Dependency | ||
{ | ||
} | ||
|
||
private IServiceProvider _provider = null!; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
var services = new ServiceCollection(); | ||
services | ||
.Configure<ServiceProviderAdvancedOptions>(opt => opt.AllowRootProviderResolve = true) | ||
.AddSingleton<Dependency>() | ||
.AddDefer(); | ||
|
||
_provider = services.BuildServiceProvider(); | ||
} | ||
|
||
[Benchmark] | ||
public void ResolveDefer() | ||
{ | ||
var defer = _provider.GetRequiredService<Defer<Dependency>>(); | ||
_ = defer.Value; | ||
} | ||
|
||
[Benchmark] | ||
public void ResolveIDefer() | ||
{ | ||
var defer = _provider.GetRequiredService<IDefer<Dependency>>(); | ||
_ = defer.Value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using BenchmarkDotNet.Configs; | ||
using BenchmarkDotNet.Diagnosers; | ||
using BenchmarkDotNet.Running; | ||
using Benchmarks; | ||
|
||
new DeferBenchmarks().Setup(); | ||
var config = ManualConfig | ||
.Create(DefaultConfig.Instance) | ||
.AddDiagnoser(MemoryDiagnoser.Default); | ||
|
||
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, config); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text.Json.Nodes; | ||
|
||
string resultsDir = "./BenchmarkDotNet.Artifacts/results"; | ||
string resultsFile = "Combined.Benchmarks"; | ||
string searchPattern = "*-report-full-compressed.json"; | ||
|
||
var resultsPath = Path.Combine(resultsDir, resultsFile + ".json"); | ||
|
||
if (!Directory.Exists(resultsDir)) | ||
{ | ||
throw new DirectoryNotFoundException($"Directory not found '{resultsDir}'"); | ||
} | ||
|
||
if (File.Exists(resultsPath)) | ||
{ | ||
File.Delete(resultsPath); | ||
} | ||
|
||
var reports = Directory.GetFiles(resultsDir, searchPattern, SearchOption.TopDirectoryOnly).ToArray(); | ||
if (!reports.Any()) | ||
{ | ||
throw new FileNotFoundException($"Reports not found '{searchPattern}'"); | ||
} | ||
|
||
var combinedReport = JsonNode.Parse(File.ReadAllText(reports.First()))!; | ||
var title = combinedReport["Title"]!; | ||
var benchmarks = combinedReport["Benchmarks"]!.AsArray(); | ||
// Rename title whilst keeping original timestamp | ||
combinedReport["Title"] = $"{resultsFile}{title.GetValue<string>()[^16..]}"; | ||
|
||
foreach (var report in reports.Skip(1)) | ||
{ | ||
var array = JsonNode.Parse(File.ReadAllText(report))!["Benchmarks"]!.AsArray(); | ||
foreach (var benchmark in array) | ||
{ | ||
// Double parse avoids "The node already has a parent" exception | ||
benchmarks.Add(JsonNode.Parse(benchmark!.ToJsonString())!); | ||
} | ||
} | ||
|
||
File.WriteAllText(resultsPath, combinedReport.ToString()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters