Skip to content

Commit 64edabf

Browse files
Add useful scripts.
1 parent 1af0996 commit 64edabf

File tree

2 files changed

+220
-0
lines changed

2 files changed

+220
-0
lines changed

ci-local.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
$env:CI = "true"
2+
$env:SIXLABORS_TESTING = "True"
3+
4+
$solution = Join-Path $PSScriptRoot "ImageSharp.Drawing.sln"
5+
6+
# Build (ci-build.ps1 net8.0)
7+
dotnet clean $solution -c Release
8+
dotnet build $solution -c Release -f net8.0
9+
10+
# Pack (ci-pack.ps1)
11+
dotnet clean $solution -c Release
12+
dotnet pack $solution -c Release --output "$PSScriptRoot/artifacts"
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
<#
2+
Runs a fixed set of DrawingThroughputBenchmark cases and emits the results as a
3+
markdown pipe table.
4+
5+
Run from the repository root:
6+
7+
.\run-drawing-throughput-benchmarks.ps1
8+
9+
The script writes the same markdown table to:
10+
11+
.\drawing-throughput-benchmark-results.md
12+
13+
Scenario meanings:
14+
15+
- SingleImage:
16+
Keeps concurrent requests at 1 and varies drawing parallelism only. Use this
17+
to measure scaling of a single render request.
18+
- ServiceThroughput:
19+
Varies the split between outer request concurrency and inner drawing
20+
parallelism. Use this to see which balance gives the best host throughput.
21+
22+
Notes:
23+
24+
- The case matrix lives in $cases below. Edit that list to add or remove runs.
25+
- The script expects the benchmark to print TotalSeconds and MegaPixelsPerSec.
26+
#>
27+
28+
$proj = "tests/ImageSharp.Drawing.ManualBenchmarks/ImageSharp.Drawing.ManualBenchmarks.csproj"
29+
$outputPath = Join-Path $PSScriptRoot "drawing-throughput-benchmark-results.md"
30+
31+
# Fixed benchmark matrix for the two investigation modes described above.
32+
$cases = @(
33+
[pscustomobject]@{
34+
Scenario = "SingleImage"
35+
Size = "Large"
36+
Width = 2000
37+
Height = 2000
38+
Seconds = 10
39+
ConcurrentRequests = 1
40+
Parallelism = 1
41+
}
42+
[pscustomobject]@{
43+
Scenario = "SingleImage"
44+
Size = "Large"
45+
Width = 2000
46+
Height = 2000
47+
Seconds = 10
48+
ConcurrentRequests = 1
49+
Parallelism = 8
50+
}
51+
[pscustomobject]@{
52+
Scenario = "SingleImage"
53+
Size = "Large"
54+
Width = 2000
55+
Height = 2000
56+
Seconds = 10
57+
ConcurrentRequests = 1
58+
Parallelism = 16
59+
}
60+
[pscustomobject]@{
61+
Scenario = "SingleImage"
62+
Size = "Small"
63+
Width = 200
64+
Height = 200
65+
Seconds = 10
66+
ConcurrentRequests = 1
67+
Parallelism = 1
68+
}
69+
[pscustomobject]@{
70+
Scenario = "SingleImage"
71+
Size = "Small"
72+
Width = 200
73+
Height = 200
74+
Seconds = 10
75+
ConcurrentRequests = 1
76+
Parallelism = 8
77+
}
78+
[pscustomobject]@{
79+
Scenario = "SingleImage"
80+
Size = "Small"
81+
Width = 200
82+
Height = 200
83+
Seconds = 10
84+
ConcurrentRequests = 1
85+
Parallelism = 16
86+
}
87+
[pscustomobject]@{
88+
Scenario = "ServiceThroughput"
89+
Size = "Large"
90+
Width = 2000
91+
Height = 2000
92+
Seconds = 10
93+
ConcurrentRequests = 8
94+
Parallelism = 1
95+
}
96+
[pscustomobject]@{
97+
Scenario = "ServiceThroughput"
98+
Size = "Large"
99+
Width = 2000
100+
Height = 2000
101+
Seconds = 10
102+
ConcurrentRequests = 4
103+
Parallelism = 2
104+
}
105+
[pscustomobject]@{
106+
Scenario = "ServiceThroughput"
107+
Size = "Large"
108+
Width = 2000
109+
Height = 2000
110+
Seconds = 10
111+
ConcurrentRequests = 2
112+
Parallelism = 4
113+
}
114+
[pscustomobject]@{
115+
Scenario = "ServiceThroughput"
116+
Size = "Large"
117+
Width = 2000
118+
Height = 2000
119+
Seconds = 10
120+
ConcurrentRequests = 1
121+
Parallelism = 8
122+
}
123+
)
124+
125+
function Parse-Decimal([string]$text)
126+
{
127+
# Benchmark output may use either decimal separator depending on locale.
128+
$normalized = $text.Replace(",", ".")
129+
return [double]::Parse($normalized, [System.Globalization.CultureInfo]::InvariantCulture)
130+
}
131+
132+
function Run-Case($case)
133+
{
134+
Write-Host ("Running {0} {1}: {2}x{3}, c={4}, p={5}" -f `
135+
$case.Scenario, `
136+
$case.Size, `
137+
$case.Width, `
138+
$case.Height, `
139+
$case.ConcurrentRequests, `
140+
$case.Parallelism)
141+
142+
$output = & dotnet run --project $proj -c Release -- `
143+
-m Tiger `
144+
-w $case.Width `
145+
-h $case.Height `
146+
-s $case.Seconds `
147+
-c $case.ConcurrentRequests `
148+
-p $case.Parallelism 2>&1
149+
150+
$exitCode = $LASTEXITCODE
151+
$outputText = ($output | ForEach-Object { $_.ToString() }) -join [Environment]::NewLine
152+
153+
if ($exitCode -ne 0)
154+
{
155+
throw "Benchmark run failed with exit code $exitCode.$([Environment]::NewLine)$outputText"
156+
}
157+
158+
$secondsMatch = [regex]::Match($outputText, "TotalSeconds:\s*([0-9]+(?:[.,][0-9]+)?)")
159+
$megaPixelsMatch = [regex]::Match($outputText, "MegaPixelsPerSec:\s*([0-9]+(?:[.,][0-9]+)?)")
160+
161+
if (!$secondsMatch.Success -or !$megaPixelsMatch.Success)
162+
{
163+
throw "Failed to parse benchmark output.$([Environment]::NewLine)$outputText"
164+
}
165+
166+
[pscustomobject]@{
167+
Scenario = $case.Scenario
168+
Size = $case.Size
169+
Width = $case.Width
170+
Height = $case.Height
171+
ConcurrentRequests = $case.ConcurrentRequests
172+
Parallelism = $case.Parallelism
173+
TotalSeconds = Parse-Decimal $secondsMatch.Groups[1].Value
174+
MegaPixelsPerSec = Parse-Decimal $megaPixelsMatch.Groups[1].Value
175+
}
176+
}
177+
178+
$results = @()
179+
foreach ($case in $cases)
180+
{
181+
$results += Run-Case $case
182+
}
183+
184+
$lines = @(
185+
"| Scenario | Size | Width | Height | Concurrent Requests | Drawing Parallelism | Total Seconds | MegaPixelsPerSec |"
186+
"| --- | --- | ---: | ---: | ---: | ---: | ---: | ---: |"
187+
)
188+
189+
foreach ($result in $results)
190+
{
191+
$lines += ("| {0} | {1} | {2} | {3} | {4} | {5} | {6:F2} | {7:F2} |" -f `
192+
$result.Scenario, `
193+
$result.Size, `
194+
$result.Width, `
195+
$result.Height, `
196+
$result.ConcurrentRequests, `
197+
$result.Parallelism, `
198+
$result.TotalSeconds, `
199+
$result.MegaPixelsPerSec)
200+
}
201+
202+
$markdown = $lines -join [Environment]::NewLine
203+
Set-Content -Path $outputPath -Value $markdown
204+
205+
Write-Host ""
206+
Write-Host $markdown
207+
Write-Host ""
208+
Write-Host "Saved markdown results to $outputPath"

0 commit comments

Comments
 (0)