Skip to content

Commit 20301ed

Browse files
committed
Move to BlazorSSR project
1 parent adf3c1e commit 20301ed

File tree

9 files changed

+97
-28
lines changed

9 files changed

+97
-28
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Fortunes</title>
5+
</head>
6+
<body>
7+
<table>
8+
<tr><th>id</th><th>message</th></tr>
9+
@foreach (var item in Rows)
10+
{
11+
<tr><td>@item.Id</td><td>@item.Message</td></tr>
12+
}
13+
</table>
14+
</body>
15+
</html>
16+
@code {
17+
[Parameter]
18+
public required List<Fortune> Rows { get; set; }
19+
}

src/BenchmarksApps/TechEmpower/BlazorSSR/Database/Db.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public async Task<List<Fortune>> LoadFortunesRowsDapper()
2222
await using var connection = _dataSource.CreateConnection();
2323
var result = (await connection.QueryAsync<Fortune>($"SELECT id, message FROM fortune")).AsList();
2424

25-
result.Add(new Fortune { Id = 0, Message = "Additional fortune added at request time." });
25+
result.Add(new() { Id = 0, Message = "Additional fortune added at request time." });
2626
result.Sort(FortuneSortComparison);
2727

2828
return result;
@@ -37,11 +37,36 @@ public async Task<List<Fortune>> LoadFortunesRowsEf(AppDbContext dbContext)
3737
result.Add(fortune);
3838
}
3939

40-
result.Add(new Fortune { Id = 0, Message = "Additional fortune added at request time." });
40+
result.Add(new() { Id = 0, Message = "Additional fortune added at request time." });
4141
result.Sort(FortuneSortComparison);
4242

4343
return result;
4444
}
4545

46+
public Task<List<Fortune>> LoadFortunesRowsNoDb()
47+
{
48+
// Benchmark requirements explicitly prohibit pre-initializing the list size
49+
var result = new List<Fortune>
50+
{
51+
new() { Id = 1, Message = "fortune: No such file or directory" },
52+
new() { Id = 2, Message = "A computer scientist is someone who fixes things that aren't broken." },
53+
new() { Id = 3, Message = "After enough decimal places, nobody gives a damn." },
54+
new() { Id = 4, Message = "A bad random number generator: 1, 1, 1, 1, 1, 4.33e+67, 1, 1, 1" },
55+
new() { Id = 5, Message = "A computer program does what you tell it to do, not what you want it to do." },
56+
new() { Id = 6, Message = "Emacs is a nice operating system, but I prefer UNIX. — Tom Christaensen" },
57+
new() { Id = 7, Message = "Any program that runs right is obsolete." },
58+
new() { Id = 8, Message = "A list is only as strong as its weakest link. — Donald Knuth" },
59+
new() { Id = 9, Message = "Feature: A bug with seniority." },
60+
new() { Id = 10, Message = "Computers make very fast, very accurate mistakes." },
61+
new() { Id = 11, Message = "<script>alert(\"This should not be displayed in a browser alert box.\");</script>" },
62+
new() { Id = 12, Message = "フレームワークのベンチマーク" },
63+
new() { Id = 0, Message = "Additional fortune added at request time." }
64+
};
65+
66+
result.Sort(FortuneSortComparison);
67+
68+
return Task.FromResult(result);
69+
}
70+
4671
ValueTask IAsyncDisposable.DisposeAsync() => _dataSource.DisposeAsync();
4772
}

src/BenchmarksApps/TechEmpower/Minimal/FortunesRazorParameters.cs renamed to src/BenchmarksApps/TechEmpower/BlazorSSR/FortunesRazorParameters.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
using System.Collections;
22
using System.Diagnostics.CodeAnalysis;
3-
using Minimal.Models;
4-
using Minimal.Templates;
3+
using BlazorSSR.Components;
4+
using BlazorSSR.Models;
55

6-
namespace Minimal;
6+
namespace BlazorSSR;
77

88
internal readonly struct FortunesRazorParameters(List<Fortune> model) : IReadOnlyDictionary<string, object?>
99
{
10-
private const string ModelKeyName = nameof(FortunesRazor.Model);
10+
private const string ModelKeyName = nameof(FortunesParameters.Rows);
1111

1212
private readonly KeyValuePair<string, object?> _modelKvp = new(ModelKeyName, model);
1313

src/BenchmarksApps/TechEmpower/BlazorSSR/Program.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@
3939
app.MapGet("/direct/fortunes", () => new RazorComponentResult<Fortunes>());
4040
app.MapGet("/direct/fortunes-ef", () => new RazorComponentResult<FortunesEf>());
4141

42+
app.MapGet("/direct/fortunes/params", async (HttpContext context, Db db) => {
43+
var fortunes = await db.LoadFortunesRowsDapper();
44+
//var fortunes = await db.LoadFortunesRowsNoDb(); // Don't call the database
45+
var parameters = new Dictionary<string, object?> { { nameof(FortunesParameters.Rows), fortunes } };
46+
//var parameters = new FortunesRazorParameters(fortunes); // Custom parameters class to avoid allocating a Dictionary
47+
var result = new RazorComponentResult<FortunesParameters>(parameters)
48+
{
49+
PreventStreamingRendering = true
50+
};
51+
return result;
52+
});
53+
4254
app.Lifetime.ApplicationStarted.Register(() => Console.WriteLine("Application started. Press Ctrl+C to shut down."));
4355
app.Lifetime.ApplicationStopping.Register(() => Console.WriteLine("Application is shutting down..."));
4456

src/BenchmarksApps/TechEmpower/BlazorSSR/blazorssr.benchmarks.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,39 @@ scenarios:
5151
presetHeaders: html
5252
path: /fortunes-ef
5353

54+
fortunes-direct:
55+
db:
56+
job: postgresql
57+
application:
58+
job: blazorssr
59+
load:
60+
job: wrk
61+
variables:
62+
presetHeaders: html
63+
path: /direct/fortunes
64+
65+
fortunes-direct-ef:
66+
db:
67+
job: postgresql
68+
application:
69+
job: blazorssr
70+
load:
71+
job: wrk
72+
variables:
73+
presetHeaders: html
74+
path: /direct/fortunes-ef
75+
76+
fortunes-direct-params:
77+
db:
78+
job: postgresql
79+
application:
80+
job: blazorssr
81+
load:
82+
job: wrk
83+
variables:
84+
presetHeaders: html
85+
path: /direct/fortunes/params
86+
5487
profiles:
5588
# this profile uses the local folder as the source
5689
# instead of the public repository

src/BenchmarksApps/TechEmpower/Minimal/Program.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
// Add services to the container.
2424
builder.Services.AddSingleton(new Db(appSettings));
25-
builder.Services.AddRazorComponents();
2625
builder.Services.AddSingleton(CreateHtmlEncoder());
2726

2827
var app = builder.Build();
@@ -47,18 +46,6 @@
4746
return template;
4847
});
4948

50-
app.MapGet("/fortunes/razor", async (HttpContext context, Db db) => {
51-
var fortunes = await db.LoadFortunesRows();
52-
//var fortunes = await db.LoadFortunesRowsNoDb(); // Don't call the database
53-
var parameters = new Dictionary<string, object?> { { nameof(FortunesRazor.Model), fortunes } };
54-
//var parameters = new FortunesRazorParameters(fortunes); // Custom parameters class to avoid allocating a Dictionary
55-
var result = new RazorComponentResult<FortunesRazor>(parameters)
56-
{
57-
PreventStreamingRendering = true
58-
};
59-
return result;
60-
});
61-
6249
app.MapGet("/queries/{count}", async (Db db, int count) => await db.LoadMultipleQueriesRows(count));
6350

6451
app.MapGet("/queries/{count}/result", async (Db db, int count) => Results.Json(await db.LoadMultipleQueriesRows(count)));

src/BenchmarksApps/TechEmpower/Minimal/Templates/FortunesRazor.razor

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/BenchmarksApps/TechEmpower/Minimal/Templates/_Imports.razor

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/BenchmarksApps/TechEmpower/Minimal/minimal.benchmarks.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ scenarios:
7878
presetHeaders: html
7979
path: /fortunes
8080

81-
fortunes_razor:
81+
fortunes_result:
8282
db:
8383
job: postgresql
8484
application:
@@ -87,7 +87,7 @@ scenarios:
8787
job: wrk
8888
variables:
8989
presetHeaders: html
90-
path: /fortunes/razor
90+
path: /fortunes/result
9191

9292
single_query:
9393
db:

0 commit comments

Comments
 (0)