Skip to content

Commit

Permalink
Add detailed benchmark of all constructors, part 1 and part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
eduherminio committed Dec 4, 2023
1 parent 2579054 commit 91038ac
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,34 @@ jobs:
name: artifacts-${{ matrix.os }}-${{ github.run_number }}-individually
path: ./src/AoC_${{ env.YEAR }}.Benchmarks/BenchmarkDotNet.Artifacts/results/
if-no-files-found: error

benchmark-detailed:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
fail-fast: false

steps:
- uses: actions/checkout@v2

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Build
run: dotnet build -c Release

- name: Run All_Days_Benchmark
run: dotnet run -c Release --no-build --filter "*All_Days_Detailed_Benchmark*"
working-directory: ./tests/AoC_${{ env.YEAR }}.Benchmarks

- name: 'Upload ${{ matrix.os }} artifacts'
continue-on-error: true
uses: actions/upload-artifact@v2
with:
name: artifacts-${{ matrix.os }}-${{ github.run_number }}-detailed
path: ./src/AoC_${{ env.YEAR }}.Benchmarks/BenchmarkDotNet.Artifacts/results/
if-no-files-found: error
45 changes: 45 additions & 0 deletions tests/AoC_2023.Benchmarks/All_Days_Detailed_Benchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using AoCHelper;
using System.Reflection;

namespace AoC_2023.Benchmarks;

#pragma warning disable IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code
#pragma warning disable IL2067 // Target parameter argument does not satisfy 'DynamicallyAccessedMembersAttribute' in call to target method. The parameter of method does not have matching annotations.
#pragma warning disable S2365 // Properties should not make collection or array copies
public class All_Days_Detailed_Benchmark : BaseDayBenchmark
{
public static List<Type>? AllDayTypes => Assembly.GetAssembly(typeof(Day_01))
?.GetTypes()
?.Where(type => typeof(BaseProblem).IsAssignableFrom(type) && !type.IsInterface && !type.IsAbstract)
?.ToList();

public static List<BaseDay?>? AllDays => Assembly.GetAssembly(typeof(Day_01))
?.GetTypes()
?.Where(type => typeof(BaseDay).IsAssignableFrom(type) && !type.IsInterface && !type.IsAbstract)
?.Select(type => Activator.CreateInstance(type) as BaseDay)
.ToList();

[Benchmark]
[ArgumentsSource(nameof(AllDayTypes))]
public object? Constructor(Type day)
{
return Activator.CreateInstance(day) as BaseDay;
}

[Benchmark]
[ArgumentsSource(nameof(AllDays))]
public async ValueTask<string> Part1(BaseDay day)
{
return await day.Solve_1();
}

[Benchmark]
[ArgumentsSource(nameof(AllDays))]
public async ValueTask<string> Part2(BaseDay day)
{
return await day.Solve_2();
}
}
#pragma warning restore IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code
#pragma warning restore IL2067 // Target parameter argument does not satisfy 'DynamicallyAccessedMembersAttribute' in call to target method. The parameter of method does not have matching annotations.
#pragma warning restore S2365 // Properties should not make collection or array copies

0 comments on commit 91038ac

Please sign in to comment.