|
| 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 |
0 commit comments