Skip to content

Commit fdcb943

Browse files
committed
Update benchmarks nightly
1 parent e5bed9a commit fdcb943

File tree

5 files changed

+198
-542
lines changed

5 files changed

+198
-542
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<#
2+
.SYNOPSIS
3+
Runs benchmarks and updates the performance documentation page.
4+
5+
.DESCRIPTION
6+
This script runs the Foundatio.Mediator benchmarks using BenchmarkDotNet,
7+
then parses the CSV results and generates a compact markdown table for
8+
the docs/guide/performance.md page.
9+
10+
.PARAMETER SkipBenchmarks
11+
Skip running benchmarks and only update docs from existing results.
12+
13+
.EXAMPLE
14+
./Update-BenchmarkDocs.ps1
15+
16+
.EXAMPLE
17+
./Update-BenchmarkDocs.ps1 -SkipBenchmarks
18+
#>
19+
20+
param(
21+
[switch]$SkipBenchmarks
22+
)
23+
24+
$ErrorActionPreference = 'Stop'
25+
26+
# Configuration - .github/scripts -> .github -> repo root (2 levels up)
27+
$RepoRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
28+
if (-not $RepoRoot -or -not (Test-Path $RepoRoot)) {
29+
$RepoRoot = Get-Location
30+
}
31+
32+
$BenchmarkProject = Join-Path $RepoRoot 'benchmarks/Foundatio.Mediator.Benchmarks'
33+
$ResultsFile = Join-Path $BenchmarkProject 'BenchmarkDotNet.Artifacts/results/Foundatio.Mediator.Benchmarks.CoreBenchmarks-report.csv'
34+
$PerfDoc = Join-Path $RepoRoot 'docs/guide/performance.md'
35+
36+
# Run benchmarks if not skipped
37+
if (-not $SkipBenchmarks) {
38+
Write-Host "Running benchmarks..." -ForegroundColor Cyan
39+
Push-Location $BenchmarkProject
40+
try {
41+
dotnet run -c Release -- --exporters csv
42+
if ($LASTEXITCODE -ne 0) {
43+
throw "Benchmark run failed with exit code $LASTEXITCODE"
44+
}
45+
}
46+
finally {
47+
Pop-Location
48+
}
49+
}
50+
51+
# Verify results file exists
52+
if (-not (Test-Path $ResultsFile)) {
53+
throw "Benchmark results file not found: $ResultsFile"
54+
}
55+
56+
Write-Host "Parsing benchmark results..." -ForegroundColor Cyan
57+
58+
# Parse CSV and build markdown table
59+
$csv = Import-Csv $ResultsFile
60+
$currentDate = Get-Date -Format 'yyyy-MM-dd'
61+
62+
# Build the markdown content
63+
$markdown = @"
64+
# Performance
65+
66+
Foundatio Mediator achieves near-direct call performance through C# interceptors and source generators, eliminating runtime reflection.
67+
68+
## Benchmark Results
69+
70+
> 📊 **Last Updated:** $currentDate
71+
> 🔧 **Generated automatically by [GitHub Actions](https://github.com/FoundatioFx/Foundatio.Mediator/actions/workflows/benchmarks.yml)**
72+
73+
| Method | Mean | Allocated |
74+
|:-------|-----:|----------:|
75+
"@
76+
77+
foreach ($row in $csv) {
78+
$markdown += "`n| $($row.Method) | $($row.Mean) | $($row.Allocated) |"
79+
}
80+
81+
$markdown += @"
82+
83+
84+
## Running Benchmarks Locally
85+
86+
``````bash
87+
cd benchmarks/Foundatio.Mediator.Benchmarks
88+
dotnet run -c Release
89+
``````
90+
"@
91+
92+
# Write the file
93+
$markdown | Out-File -FilePath $PerfDoc -Encoding utf8 -NoNewline
94+
95+
Write-Host "Performance documentation updated: $PerfDoc" -ForegroundColor Green

.github/workflows/benchmarks.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Benchmarks
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
# Run daily at 2:00 AM UTC
7+
- cron: '0 2 * * *'
8+
push:
9+
branches:
10+
- main
11+
paths:
12+
- '.github/scripts/Update-BenchmarkDocs.ps1'
13+
- '.github/workflows/benchmarks.yml'
14+
15+
jobs:
16+
benchmark:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: write
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0
26+
27+
- name: Setup .NET
28+
uses: actions/setup-dotnet@v4
29+
with:
30+
dotnet-version: '10.0.x'
31+
32+
- name: Restore dependencies
33+
run: dotnet restore
34+
35+
- name: Build solution
36+
run: dotnet build -c Release --no-restore
37+
38+
- name: Run benchmarks and update docs
39+
shell: pwsh
40+
run: .github/scripts/Update-BenchmarkDocs.ps1
41+
42+
- name: Commit and push changes
43+
run: |
44+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
45+
git config --local user.name "github-actions[bot]"
46+
47+
# Check if there are changes to commit
48+
if git diff --quiet docs/guide/performance.md; then
49+
echo "No changes to commit"
50+
exit 0
51+
fi
52+
53+
git add docs/guide/performance.md
54+
git commit -m "📊 Update benchmark results [skip ci]"
55+
56+
# Pull with rebase in case changes were pushed while benchmarks ran
57+
git pull --rebase origin main
58+
git push

.vscode/tasks.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@
3030
"problemMatcher": [
3131
"$msCompile"
3232
]
33+
},
34+
{
35+
"label": "update benchmark docs",
36+
"type": "shell",
37+
"command": "pwsh",
38+
"args": [
39+
"-File",
40+
"${workspaceFolder}/.github/scripts/Update-BenchmarkDocs.ps1"
41+
],
42+
"problemMatcher": []
3343
}
3444
]
3545
}

docs/.vitepress/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default withMermaid(defineConfig({
5353
items: [
5454
{ text: 'Cascading Messages', link: '/guide/cascading-messages' },
5555
{ text: 'Streaming Handlers', link: '/guide/streaming-handlers' },
56-
{ text: 'Performance & Interceptors', link: '/guide/performance' },
56+
{ text: 'Performance', link: '/guide/performance' },
5757
{ text: 'Configuration Options', link: '/guide/configuration' },
5858
{ text: 'Troubleshooting', link: '/guide/troubleshooting' }
5959
]

0 commit comments

Comments
 (0)