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