@@ -24,7 +24,7 @@ namespace Wasm.Performance.Driver
24
24
public class Program
25
25
{
26
26
static readonly TimeSpan Timeout = TimeSpan . FromMinutes ( 3 ) ;
27
- static TaskCompletionSource < List < BenchmarkResult > > benchmarkResult = new TaskCompletionSource < List < BenchmarkResult > > ( ) ;
27
+ static TaskCompletionSource < BenchmarkResult > benchmarkResult = new TaskCompletionSource < BenchmarkResult > ( ) ;
28
28
29
29
public static async Task < int > Main ( string [ ] args )
30
30
{
@@ -57,42 +57,36 @@ public static async Task<int> Main(string[] args)
57
57
browser . Url = launchUrl ;
58
58
browser . Navigate ( ) ;
59
59
60
- var appSize = GetBlazorAppSize ( ) ;
61
- await Task . WhenAll ( benchmarkResult . Task , appSize ) ;
62
- FormatAsBenchmarksOutput ( benchmarkResult . Task . Result , appSize . Result ) ;
60
+ FormatAsBenchmarksOutput ( benchmarkResult . Task . Result ) ;
63
61
64
62
Console . WriteLine ( "Done executing benchmark" ) ;
65
63
return 0 ;
66
64
}
67
65
68
- internal static void SetBenchmarkResult ( List < BenchmarkResult > result )
66
+ internal static void SetBenchmarkResult ( BenchmarkResult result )
69
67
{
70
68
benchmarkResult . TrySetResult ( result ) ;
71
69
}
72
70
73
- private static void FormatAsBenchmarksOutput ( List < BenchmarkResult > results , ( long publishSize , long compressedSize ) sizes )
71
+ private static void FormatAsBenchmarksOutput ( BenchmarkResult benchmarkResult )
74
72
{
75
73
// Sample of the the format: https://github.com/aspnet/Benchmarks/blob/e55f9e0312a7dd019d1268c1a547d1863f0c7237/src/Benchmarks/Program.cs#L51-L67
76
74
var output = new BenchmarkOutput ( ) ;
77
- foreach ( var result in results )
75
+ output . Metadata . Add ( new BenchmarkMetadata
78
76
{
79
- var scenarioName = result . Descriptor . Name ;
80
- output . Metadata . Add ( new BenchmarkMetadata
81
- {
82
- Source = "BlazorWasm" ,
83
- Name = scenarioName ,
84
- ShortDescription = result . Name ,
85
- LongDescription = result . Descriptor . Description ,
86
- Format = "n2"
87
- } ) ;
77
+ Source = "BlazorWasm" ,
78
+ Name = "blazorwasm/download-size" ,
79
+ ShortDescription = "Download size (KB)" ,
80
+ LongDescription = "Download size (KB)" ,
81
+ Format = "n2" ,
82
+ } ) ;
88
83
89
- output . Measurements . Add ( new BenchmarkMeasurement
90
- {
91
- Timestamp = DateTime . UtcNow ,
92
- Name = scenarioName ,
93
- Value = result . Duration ,
94
- } ) ;
95
- }
84
+ output . Measurements . Add ( new BenchmarkMeasurement
85
+ {
86
+ Timestamp = DateTime . UtcNow ,
87
+ Name = "blazorwasm/download-size" ,
88
+ Value = ( ( float ) benchmarkResult . DownloadSize ) / 1024 ,
89
+ } ) ;
96
90
97
91
// Information about the build that this was produced from
98
92
output . Metadata . Add ( new BenchmarkMetadata
@@ -112,38 +106,25 @@ private static void FormatAsBenchmarksOutput(List<BenchmarkResult> results, (lon
112
106
? . Value ,
113
107
} ) ;
114
108
115
- // Statistics about publish sizes
116
- output . Metadata . Add ( new BenchmarkMetadata
117
- {
118
- Source = "BlazorWasm" ,
119
- Name = "blazorwasm/publish-size" ,
120
- ShortDescription = "Publish size (KB)" ,
121
- LongDescription = "Publish size (KB)" ,
122
- Format = "n2" ,
123
- } ) ;
124
-
125
- output . Measurements . Add ( new BenchmarkMeasurement
126
- {
127
- Timestamp = DateTime . UtcNow ,
128
- Name = "blazorwasm/publish-size" ,
129
- Value = sizes . publishSize / 1024 ,
130
- } ) ;
131
-
132
- output . Metadata . Add ( new BenchmarkMetadata
109
+ foreach ( var result in benchmarkResult . ScenarioResults )
133
110
{
134
- Source = "BlazorWasm" ,
135
- Name = "blazorwasm/compressed-publish-size" ,
136
- ShortDescription = "Publish size compressed app (KB)" ,
137
- LongDescription = "Publish size - compressed app (KB)" ,
138
- Format = "n2" ,
139
- } ) ;
111
+ var scenarioName = result . Descriptor . Name ;
112
+ output . Metadata . Add ( new BenchmarkMetadata
113
+ {
114
+ Source = "BlazorWasm" ,
115
+ Name = scenarioName ,
116
+ ShortDescription = result . Name ,
117
+ LongDescription = result . Descriptor . Description ,
118
+ Format = "n2"
119
+ } ) ;
140
120
141
- output . Measurements . Add ( new BenchmarkMeasurement
142
- {
143
- Timestamp = DateTime . UtcNow ,
144
- Name = "blazorwasm/compressed-publish-size" ,
145
- Value = sizes . compressedSize / 1024 ,
146
- } ) ;
121
+ output . Measurements . Add ( new BenchmarkMeasurement
122
+ {
123
+ Timestamp = DateTime . UtcNow ,
124
+ Name = scenarioName ,
125
+ Value = result . Duration ,
126
+ } ) ;
127
+ }
147
128
148
129
Console . WriteLine ( "#StartJobStatistics" ) ;
149
130
Console . WriteLine ( JsonSerializer . Serialize ( output ) ) ;
@@ -156,6 +137,12 @@ static IHost StartTestApp()
156
137
{
157
138
"--urls" , "http://127.0.0.1:0" ,
158
139
"--applicationpath" , typeof ( TestApp . Program ) . Assembly . Location ,
140
+ #if DEBUG
141
+ "--contentroot" ,
142
+ Path . GetFullPath ( typeof ( Program ) . Assembly . GetCustomAttributes < AssemblyMetadataAttribute > ( )
143
+ . First ( f => f . Key == "TestAppLocatiion" )
144
+ . Value )
145
+ #endif
159
146
} ;
160
147
161
148
var host = DevHostServerProgram . BuildWebHost ( args ) ;
@@ -216,76 +203,5 @@ static string GetListeningUrl(IHost testApp)
216
203
. Addresses
217
204
. First ( ) ;
218
205
}
219
-
220
- static async Task < ( long size , long compressedSize ) > GetBlazorAppSize ( )
221
- {
222
- var testAssembly = typeof ( TestApp . Program ) . Assembly ;
223
- var testAssemblyLocation = new FileInfo ( testAssembly . Location ) ;
224
- var testApp = new DirectoryInfo ( Path . Combine (
225
- testAssemblyLocation . Directory . FullName ,
226
- testAssembly . GetName ( ) . Name ) ) ;
227
-
228
- return ( GetDirectorySize ( testApp ) , await GetBrotliCompressedSize ( testApp ) ) ;
229
- }
230
-
231
- static long GetDirectorySize ( DirectoryInfo directory )
232
- {
233
- // This can happen if you run the app without publishing it.
234
- if ( ! directory . Exists )
235
- {
236
- return 0 ;
237
- }
238
-
239
- long size = 0 ;
240
- foreach ( var item in directory . EnumerateFileSystemInfos ( ) )
241
- {
242
- if ( item is FileInfo fileInfo )
243
- {
244
- size += fileInfo . Length ;
245
- }
246
- else if ( item is DirectoryInfo directoryInfo )
247
- {
248
- size += GetDirectorySize ( directoryInfo ) ;
249
- }
250
- }
251
-
252
- return size ;
253
- }
254
-
255
- static async Task < long > GetBrotliCompressedSize ( DirectoryInfo directory )
256
- {
257
- if ( ! directory . Exists )
258
- {
259
- return 0 ;
260
- }
261
-
262
- var tasks = new List < Task < long > > ( ) ;
263
- foreach ( var item in directory . EnumerateFileSystemInfos ( ) )
264
- {
265
- if ( item is FileInfo fileInfo )
266
- {
267
- tasks . Add ( GetCompressedFileSize ( fileInfo ) ) ;
268
- }
269
- else if ( item is DirectoryInfo directoryInfo )
270
- {
271
- tasks . Add ( GetBrotliCompressedSize ( directoryInfo ) ) ;
272
- }
273
- }
274
-
275
- return ( await Task . WhenAll ( tasks ) ) . Sum ( s => s ) ;
276
-
277
- async Task < long > GetCompressedFileSize ( FileInfo fileInfo )
278
- {
279
- using var inputStream = new FileStream ( fileInfo . FullName , FileMode . Open , FileAccess . Read , FileShare . Read , 1 , useAsync : true ) ;
280
- using var outputStream = new MemoryStream ( ) ;
281
-
282
- using ( var brotliStream = new BrotliStream ( outputStream , CompressionLevel . Optimal , leaveOpen : true ) )
283
- {
284
- await inputStream . CopyToAsync ( brotliStream ) ;
285
- }
286
-
287
- return outputStream . Length ;
288
- }
289
- }
290
206
}
291
207
}
0 commit comments