From f8d43c552459361b6253969dd157de415eab2fae Mon Sep 17 00:00:00 2001 From: Soundar Anbalagan Date: Thu, 12 Jun 2025 17:23:53 +0100 Subject: [PATCH 1/7] Add benchmark workflow and update benchmarking code Introduces a new GitHub Actions workflow `benchmark-on-pr` for running benchmarks on pull requests. The workflow sets up .NET 8, checks out the code, and commits benchmark results. Updates in `Program.cs` include new using directives for BenchmarkDotNet analyzers and configurations. The benchmark report format is modified, showing a slight increase in execution time for the `RenderViewWithModelAsync` method. --- .github/workflows/dotnetcore.yml | 24 +++++++++++++++++++ .../Program.cs | 4 +++- ...rTemplatingCoreBenchMark-report-github.md} | 6 ++--- 3 files changed, 30 insertions(+), 4 deletions(-) rename benchmark/Razor.Template.Core.PerfBenchmark/results/{RazorTemplateBenchMark-report-github.md => RazorTemplatingCoreBenchMark-report-github.md} (58%) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index d3fc7bb..54a117d 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -38,3 +38,27 @@ jobs: run: dotnet build --configuration Release --no-restore - name: Test run: dotnet test --no-restore --verbosity normal + + benchmark-on-pr: + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} + + - name: Setup .NET 8 + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '8.0.x' + + - name: Run benchmark + run: dotnet run -c Release --project benchmark/Razor.Template.Core.PerfBenchmark/Razor.Template.Core.PerfBenchmark.csproj + + - name: Commit benchmark results + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git add benchmark/Razor.Template.Core.PerfBenchmark/results/RazorTemplatingCoreBenchMark-report-github.md + git commit -m "chore: update benchmark report [skip ci]" || echo "No changes to commit" + git push origin HEAD:${{ github.head_ref }} diff --git a/benchmark/Razor.Template.Core.PerfBenchmark/Program.cs b/benchmark/Razor.Template.Core.PerfBenchmark/Program.cs index b8e2114..2fa7fce 100644 --- a/benchmark/Razor.Template.Core.PerfBenchmark/Program.cs +++ b/benchmark/Razor.Template.Core.PerfBenchmark/Program.cs @@ -1,4 +1,5 @@ -using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Analysers; +using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; using BenchmarkDotNet.Diagnosers; using BenchmarkDotNet.Exporters; @@ -8,6 +9,7 @@ var config = ManualConfig.CreateMinimumViable() .AddExporter(MarkdownExporter.GitHub) + .AddAnalyser(EnvironmentAnalyser.Default) .WithArtifactsPath("."); BenchmarkRunner.Run(config); diff --git a/benchmark/Razor.Template.Core.PerfBenchmark/results/RazorTemplateBenchMark-report-github.md b/benchmark/Razor.Template.Core.PerfBenchmark/results/RazorTemplatingCoreBenchMark-report-github.md similarity index 58% rename from benchmark/Razor.Template.Core.PerfBenchmark/results/RazorTemplateBenchMark-report-github.md rename to benchmark/Razor.Template.Core.PerfBenchmark/results/RazorTemplatingCoreBenchMark-report-github.md index 01783fd..0c117e8 100644 --- a/benchmark/Razor.Template.Core.PerfBenchmark/results/RazorTemplateBenchMark-report-github.md +++ b/benchmark/Razor.Template.Core.PerfBenchmark/results/RazorTemplatingCoreBenchMark-report-github.md @@ -8,6 +8,6 @@ Unknown processor ``` -| Method | Mean | Error | StdDev | Median | Gen0 | Allocated | -|------------------------- |---------:|---------:|---------:|---------:|-------:|----------:| -| RenderViewWithModelAsync | 29.87 μs | 0.642 μs | 1.778 μs | 29.35 μs | 5.6152 | 23.16 KB | +| Method | Mean | Error | StdDev | Gen0 | Allocated | +|------------------------- |---------:|---------:|---------:|-------:|----------:| +| RenderViewWithModelAsync | 30.69 μs | 0.781 μs | 2.277 μs | 5.6152 | 23.16 KB | From e7d3d8de7661e94ebad51585b62bf39daa75f94f Mon Sep 17 00:00:00 2001 From: Soundar Anbalagan Date: Thu, 12 Jun 2025 17:25:21 +0100 Subject: [PATCH 2/7] Use .NET 9 --- .github/workflows/dotnetcore.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 54a117d..6e5a706 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -47,10 +47,10 @@ jobs: with: ref: ${{ github.head_ref }} - - name: Setup .NET 8 + - name: Setup .NET 9 uses: actions/setup-dotnet@v1 with: - dotnet-version: '8.0.x' + dotnet-version: '9.0.x' - name: Run benchmark run: dotnet run -c Release --project benchmark/Razor.Template.Core.PerfBenchmark/Razor.Template.Core.PerfBenchmark.csproj From b47d9a0caff285a92e14e4628ad6332bb3ff6d2a Mon Sep 17 00:00:00 2001 From: Soundar Anbalagan Date: Thu, 12 Jun 2025 17:27:23 +0100 Subject: [PATCH 3/7] Update benchmark to .NET 9 --- .../Razor.Template.Core.PerfBenchmark.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/Razor.Template.Core.PerfBenchmark/Razor.Template.Core.PerfBenchmark.csproj b/benchmark/Razor.Template.Core.PerfBenchmark/Razor.Template.Core.PerfBenchmark.csproj index ae08627..88c5df5 100644 --- a/benchmark/Razor.Template.Core.PerfBenchmark/Razor.Template.Core.PerfBenchmark.csproj +++ b/benchmark/Razor.Template.Core.PerfBenchmark/Razor.Template.Core.PerfBenchmark.csproj @@ -2,7 +2,7 @@ Exe - net8.0 + net9.0 enable enable From c1f30bdba17498eeb826e163bcc404fa83cf9224 Mon Sep 17 00:00:00 2001 From: Soundar Anbalagan Date: Thu, 12 Jun 2025 17:32:22 +0100 Subject: [PATCH 4/7] Ensure benchmark results directory exists Added a step in `dotnetcore.yml` to create the results directory and include a `.gitkeep` file. Updated the `git add` command to add all files in the results directory for better flexibility in committing benchmark results. --- .github/workflows/dotnetcore.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 6e5a706..93d1604 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -52,6 +52,11 @@ jobs: with: dotnet-version: '9.0.x' + - name: Ensure results directory exists + run: | + mkdir -p benchmark/Razor.Template.Core.PerfBenchmark/results + touch benchmark/Razor.Template.Core.PerfBenchmark/results/.gitkeep + - name: Run benchmark run: dotnet run -c Release --project benchmark/Razor.Template.Core.PerfBenchmark/Razor.Template.Core.PerfBenchmark.csproj @@ -59,6 +64,6 @@ jobs: run: | git config --global user.name "github-actions[bot]" git config --global user.email "github-actions[bot]@users.noreply.github.com" - git add benchmark/Razor.Template.Core.PerfBenchmark/results/RazorTemplatingCoreBenchMark-report-github.md + git add benchmark/Razor.Template.Core.PerfBenchmark/results/ git commit -m "chore: update benchmark report [skip ci]" || echo "No changes to commit" git push origin HEAD:${{ github.head_ref }} From 5304e02a6825006902e0f672f5f5960901423f76 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 12 Jun 2025 16:33:11 +0000 Subject: [PATCH 5/7] chore: update benchmark report [skip ci] --- benchmark/Razor.Template.Core.PerfBenchmark/results/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 benchmark/Razor.Template.Core.PerfBenchmark/results/.gitkeep diff --git a/benchmark/Razor.Template.Core.PerfBenchmark/results/.gitkeep b/benchmark/Razor.Template.Core.PerfBenchmark/results/.gitkeep new file mode 100644 index 0000000..e69de29 From c3a37a6ecb1b766970690a38ebd437b3b86a308b Mon Sep 17 00:00:00 2001 From: Soundar Anbalagan Date: Thu, 12 Jun 2025 17:35:13 +0100 Subject: [PATCH 6/7] Remove benchmark --- .../results/.gitkeep | 0 .../RazorTemplatingCoreBenchMark-report-github.md | 13 ------------- 2 files changed, 13 deletions(-) delete mode 100644 benchmark/Razor.Template.Core.PerfBenchmark/results/.gitkeep delete mode 100644 benchmark/Razor.Template.Core.PerfBenchmark/results/RazorTemplatingCoreBenchMark-report-github.md diff --git a/benchmark/Razor.Template.Core.PerfBenchmark/results/.gitkeep b/benchmark/Razor.Template.Core.PerfBenchmark/results/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/benchmark/Razor.Template.Core.PerfBenchmark/results/RazorTemplatingCoreBenchMark-report-github.md b/benchmark/Razor.Template.Core.PerfBenchmark/results/RazorTemplatingCoreBenchMark-report-github.md deleted file mode 100644 index 0c117e8..0000000 --- a/benchmark/Razor.Template.Core.PerfBenchmark/results/RazorTemplatingCoreBenchMark-report-github.md +++ /dev/null @@ -1,13 +0,0 @@ -``` - -BenchmarkDotNet v0.15.1, Windows 11 (10.0.26100.4349/24H2/2024Update/HudsonValley) -Unknown processor -.NET SDK 9.0.301 - [Host] : .NET 8.0.16 (8.0.1625.21506), X64 RyuJIT AVX2 - DefaultJob : .NET 8.0.16 (8.0.1625.21506), X64 RyuJIT AVX2 - - -``` -| Method | Mean | Error | StdDev | Gen0 | Allocated | -|------------------------- |---------:|---------:|---------:|-------:|----------:| -| RenderViewWithModelAsync | 30.69 μs | 0.781 μs | 2.277 μs | 5.6152 | 23.16 KB | From f2ccabc1054dc7bf16266277d173a1139dca7018 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 12 Jun 2025 16:36:06 +0000 Subject: [PATCH 7/7] chore: update benchmark report [skip ci] --- benchmark/Razor.Template.Core.PerfBenchmark/results/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 benchmark/Razor.Template.Core.PerfBenchmark/results/.gitkeep diff --git a/benchmark/Razor.Template.Core.PerfBenchmark/results/.gitkeep b/benchmark/Razor.Template.Core.PerfBenchmark/results/.gitkeep new file mode 100644 index 0000000..e69de29