-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.ps1
228 lines (177 loc) · 5.83 KB
/
bench.ps1
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
param(
[string]$Configuration = 'Release',
[string[]]$Filter = @('*.Select_*'),
[switch]$All = $false,
[switch]$Select = $false,
[switch]$Where = $false,
[switch]$Take = $false,
[switch]$TakeLast = $false,
[switch]$First = $false,
[switch]$FirstWhere = $false,
[switch]$Last = $false,
[switch]$LastWhere = $false,
[switch]$Once = $false,
[switch]$Join = $false,
[switch]$NoFaslinq = $false,
[string[]]$Runtimes = @('net6.0')
)
function Clean-Folder {
param(
[String[]]$P = @('obj', 'bin'),
[switch]$R = $false,
[switch]$F = $false,
[switch]$V = $false
)
if ($V) {
Write-Host "`$P: $P"
Write-Host "`$R: $R"
Write-Host "`$F: $F"
Write-Host "`$V: $V"
}
#gci bin,obj -r
Get-ChildItem $P -Recurse:$R -Verbose:$V `
| Remove-Item -Recurse:$R -Force:$F -Verbose:$V
}
try {
[System.Collections.Generic.List[string[]]]$Names = @()
if ($All) {
[string[]]$f = @('--filter', '*')
}
else {
$f = @()
if ($Select) {
$f += '-Select'
}
if ($Where) {
$f += '-Where'
}
if ($Take) {
$f += '-Take'
}
if ($TakeLast) {
$f += '-TakeLast'
}
if ($First) {
$f += '-First'
}
if ($FirstWhere) {
$f += '-FirstWhere'
}
if ($Last) {
$f += '-Last'
}
if ($LastWhere) {
$f += '-LastWhere'
}
}
$FF = [System.String]::Join(' ', $f)
if ($Once) {
$OneIteration = '--runOncePerIteration'
}
if ($Join) {
$joinParameter = '--join'
}
if ($NoFaslinq) {
$NoFaslinqOption = '/p:DefineConstants=NO_FASLINQ'
}
else {
$NoFaslinqOption = ''
}
Push-Location
$root = Get-Location
Clean-Folder -p @('bin', 'obj', '*.artifacts') -r -f
& dotnet restore
Set-Location "$root\Faslinq.Benchmarks\"
$Runtime = [System.DateTimeOffset]::Now.ToString('G')
$frontmatter = Get-Content .\doks\benchmarks\results.yaml
$md = $frontmatter + @("# Benchmark Run at ${Runtime}", '')
$Title = 'Faslinq'
if ($NoFaslinq) {
$Title = 'Linq'
}
$md += ''
$md += "``````powershell"
$md += "dotnet publish -c $Configuration $NoFaslinqOption -f net6.0 -a x64 --self-contained"
$md += "``````"
& dotnet publish -c $Configuration $NoFaslinqOption -f net6.0 -a x64 --self-contained
Set-Location "$root\Faslinq.Benchmarks\bin\$Configuration\net6.0\win-x64\publish\"
Write-Verbose "`$Configuration: $Configuration"
Write-Verbose "`$OneIteration: $OneIteration"
Write-Verbose "`$Filter: $Filter"
$md += ''
$md += "``````powershell"
$md += "& .\Faslinq.Benchmarks.exe $OneIteration $joinParameter ${FF} --platform X64"
$md += "``````"
& .\Faslinq.Benchmarks.exe $OneIteration $joinParameter ${FF} --platform X64
Set-Location "$root\Faslinq.Benchmarks\bin\$Configuration\net6.0\win-x64\publish\BenchmarkDotNet.Artifacts\results"
$mds = Get-ChildItem '*github.md' -ErrorAction Stop `
| Sort-Object -Property CreationTime -Descending -Top 1 `
| Get-Content;
$json = Get-ChildItem '*report-full.json' -ErrorAction Stop `
| Sort-Object -Property CreationTime -Descending -Top 1;
$faslinqReport = Get-ChildItem 'Faslinq-*.json' -ErrorAction Stop `
| Sort-Object -Property CreationTime -Descending -Top 1;
for ($i = 0; $i -lt $mds.Count; $i += 1) {
$line = $mds[$i]
if ($line -eq "``````") {
$mds[$i] = $line + [System.Environment]::NewLine
}
}
$md += '', "## ${Title}", ''
$md += $mds
if ($NoFaslinq) {
Remove-Item *github.md
Set-Location "$root\Faslinq.Benchmarks\"
$md += ''
$md += "``````powershell"
$md += "dotnet publish -c $Configuration -f net6.0 -a x64 --self-contained"
$md += "``````"
& dotnet publish -c $Configuration -f net6.0 -a x64 --self-contained
Set-Location "$root\Faslinq.Benchmarks\bin\$Configuration\net6.0\win-x64\publish\"
$md += ''
$md += "``````powershell"
$md += "& .\Faslinq.Benchmarks.exe $OneIteration $joinParameter ${FF} --platform X64"
$md += "``````"
& .\Faslinq.Benchmarks.exe $OneIteration $joinParameter ${FF} --platform X64
Set-Location "$root\Faslinq.Benchmarks\bin\$Configuration\net6.0\win-x64\publish\BenchmarkDotNet.Artifacts\results"
$md += ''
$mds = Get-ChildItem '*github.md' -ErrorAction Stop
for ($i = 0; $i -lt $mds.Count; $i += 1) {
$line = $mds[$i]
if ($line -eq "``````") {
$mds[$i] = $line + [System.Environment]::NewLine
}
}
$md += $mds | Get-Content
}
foreach ($name in $Names) {
$Key = $name[0] + '|'
$Value = $name[1] + '|'
$md = $md.Replace($Key, $Value)
}
Write-Host $md
$resultsFile = "$root\results.md"
$md | Out-File $resultsFile -Force
$doksFile = "$root\doks\benchmarks\results.md"
$jsonFile = "$root\doks\benchmarks\full-report.json"
$faslinqFile = "$root\doks\benchmarks\faslinq-report.json"
Copy-Item $resultsFile -Destination $doksFile -Verbose
Copy-Item $json -Destination $jsonFile -Verbose
Copy-Item $faslinqReport -Destination $faslinqFile -Verbose
$edge = Get-Command *edge.exe
$wsl = Get-Command wsl
if($wsl) {
Set-Location "$root\doks"
Start-Process $wsl -NoNewWindow -ArgumentList '--exec', 'jekyll clean; jekyll build; jekyll serve;'
if ($edge) {
& $edge "http://localhost:4000/"
}
} else {
if ($edge) {
& $edge $resultsFile
}
}
}
finally {
Pop-Location
}