param( [string]$OutputPath = "" ) $ErrorActionPreference = "Stop" $repositoryRoot = Split-Path -Parent $PSScriptRoot if ([string]::IsNullOrWhiteSpace($OutputPath)) { $OutputPath = Join-Path $repositoryRoot "dist/gateway-benchmarks.txt" } elseif (-not [System.IO.Path]::IsPathRooted($OutputPath)) { $OutputPath = Join-Path $repositoryRoot $OutputPath } $OutputPath = [System.IO.Path]::GetFullPath($OutputPath) if ([System.IO.Path]::GetExtension($OutputPath) -ne ".txt") { throw "OutputPath must end in .txt" } $revision = (& git -C $repositoryRoot rev-parse --verify HEAD 2>$null).Trim() if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($revision)) { throw "could not resolve the current Git revision" } $outputDirectory = Split-Path -Parent $OutputPath New-Item -ItemType Directory -Force -Path $outputDirectory | Out-Null @( "proxy-pool gateway microbenchmarks", "revision: $revision", "generated_at_utc: $([DateTime]::UtcNow.ToString('O'))", "go_version: $((& go version).Trim())", "" ) | Set-Content -LiteralPath $OutputPath -Encoding utf8 function Invoke-Benchmark { param( [string]$Package, [string]$Pattern ) $arguments = @("test", "-count=1", "-run", "^$", "-bench", $Pattern, "-benchtime=1x", "-benchmem", $Package) "==> go $($arguments -join ' ')" | Tee-Object -FilePath $OutputPath -Append $lines = & go @arguments 2>&1 $exitCode = $LASTEXITCODE $lines | Tee-Object -FilePath $OutputPath -Append if ($exitCode -ne 0) { throw "benchmark failed with exit code $exitCode" } "" | Tee-Object -FilePath $OutputPath -Append } Invoke-Benchmark -Package "./internal/gateway/dispatch" -Pattern "BenchmarkAcquire100k(Indexed|RoutingRoundRobin)" Invoke-Benchmark -Package "./internal/gateway/snapshot" -Pattern "^BenchmarkStoreApply100k$" Write-Host "benchmark evidence: $OutputPath"