From 91038ac27448d0803ada4043174dc3920fe99794 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20C=C3=A1ceres?= Date: Mon, 4 Dec 2023 22:58:07 +0100 Subject: [PATCH] Add detailed benchmark of all constructors, part 1 and part 2 --- .github/workflows/benchmarks.yml | 31 +++++++++++++ .../All_Days_Detailed_Benchmark.cs | 45 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 tests/AoC_2023.Benchmarks/All_Days_Detailed_Benchmark.cs diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index f85dbed..06084cb 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -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 diff --git a/tests/AoC_2023.Benchmarks/All_Days_Detailed_Benchmark.cs b/tests/AoC_2023.Benchmarks/All_Days_Detailed_Benchmark.cs new file mode 100644 index 0000000..6e9defe --- /dev/null +++ b/tests/AoC_2023.Benchmarks/All_Days_Detailed_Benchmark.cs @@ -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? AllDayTypes => Assembly.GetAssembly(typeof(Day_01)) + ?.GetTypes() + ?.Where(type => typeof(BaseProblem).IsAssignableFrom(type) && !type.IsInterface && !type.IsAbstract) + ?.ToList(); + + public static List? 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 Part1(BaseDay day) + { + return await day.Solve_1(); + } + + [Benchmark] + [ArgumentsSource(nameof(AllDays))] + public async ValueTask 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 \ No newline at end of file