Skip to content

Commit b99e5dd

Browse files
committed
Add a scenario for measuring navigating between components
1 parent 63b1e56 commit b99e5dd

File tree

7 files changed

+88
-10
lines changed

7 files changed

+88
-10
lines changed

src/Components/benchmarkapps/Wasm.Performance/TestApp/Pages/OrgChart.razor

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
@code
1919
{
20-
int depth = 2;
21-
int subs = 5;
20+
int depth = 1;
21+
int subs = 3;
2222
bool show;
2323

2424
protected override void OnAfterRender(bool firstRender)
@@ -35,4 +35,4 @@
3535
{
3636
show = true;
3737
}
38-
}
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
@page "/timer"
2+
@inject IJSRuntime JSRuntime
3+
@using System.Threading
4+
@implements IDisposable
5+
6+
<h1>Timer component</h1>
7+
<div style="width: 100px; height: 100px; background-color: rgb(@red, @green, @blue))">
8+
Hello world
9+
</div>
10+
11+
@code
12+
{
13+
Random random = new Random();
14+
Timer timer;
15+
int red = 128;
16+
int green = 128;
17+
int blue = 128;
18+
19+
protected override void OnInitialized()
20+
{
21+
timer = new Timer(UpdateColor, null, 300, 300);
22+
}
23+
24+
void UpdateColor(object state)
25+
{
26+
InvokeAsync(() =>
27+
{
28+
red = random.Next(0, 256);
29+
green = random.Next(0, 256);
30+
blue = random.Next(0, 256);
31+
StateHasChanged();
32+
BenchmarkEvent.Send(JSRuntime, "Finished updating color");
33+
34+
});
35+
}
36+
37+
public void Dispose() => timer.Dispose();
38+
}

src/Components/benchmarkapps/Wasm.Performance/TestApp/Shared/MainLayout.razor

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
<a href="">Home</a> |
66
<a href="renderlist">RenderList</a> |
77
<a href="json">JSON</a> |
8-
<a href="orgchart">OrgChart</a>
8+
<a href="orgchart">OrgChart</a> |
9+
<a href="timer">Timer</a>
910

10-
<hr/>
11+
<hr />
1112

1213
<div>
1314
@Body

src/Components/benchmarkapps/Wasm.Performance/TestApp/wwwroot/benchmarks/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import './appStartup.js';
44
import './renderList.js';
55
import './jsonHandling.js';
66
import './orgChart.js';
7+
import './navigation.js';
78
import { getBlazorDownloadSize } from './blazorDownloadSize.js';
89

910
new HtmlUI('E2E Performance', '#display');

src/Components/benchmarkapps/Wasm.Performance/TestApp/wwwroot/benchmarks/lib/minibench/minibench.ui.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class HtmlUI {
175175
true
176176
);
177177
this.runButton.style.display = areAllIdle ? 'block' : 'none';
178-
this.stopButton.style.display = areAllIdle ? 'none' : 'block';;
178+
this.stopButton.style.display = areAllIdle ? 'none' : 'block';
179179
}
180180

181181
get globalRunOptions() {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { group, benchmark, setup, teardown } from './lib/minibench/minibench.js';
2+
import { BlazorApp } from './util/BlazorApp.js';
3+
import { receiveEvent } from './util/BenchmarkEvents.js';
4+
5+
group('Navigation', () => {
6+
let app;
7+
8+
setup(async () => {
9+
app = new BlazorApp();
10+
await app.start();
11+
});
12+
13+
teardown(() => app.dispose());
14+
15+
// measures time to navigate between rendered components with different UI, use timers, implement IDisposables etc
16+
benchmark('Time to navigate', () =>
17+
benchmarkNavigation(app), {
18+
descriptor: {
19+
name: 'blazorwasm/navigation',
20+
description: 'Navigation - Time in ms'
21+
}
22+
});
23+
});
24+
25+
async function benchmarkNavigation(app) {
26+
const appDocument = app.window.document;
27+
app.navigateTo('renderList');
28+
let nextCompletion = receiveEvent('Finished rendering list');
29+
appDocument.querySelector('#show-list').click();
30+
await nextCompletion;
31+
32+
app.navigateTo('orgChart');
33+
nextCompletion = receiveEvent('Finished OrgChart rendering');
34+
appDocument.querySelector('#show').click();
35+
await nextCompletion;
36+
37+
nextCompletion = receiveEvent('Finished updating color');
38+
app.navigateTo('timer');
39+
await nextCompletion;
40+
}

src/Components/benchmarkapps/Wasm.Performance/TestApp/wwwroot/index.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
<link href="benchmarks/lib/minibench/style.css" rel="stylesheet" />
88
</head>
99
<body style="overflow: scroll;">
10-
<div class="container" id="display"></div>
11-
<p class="container px-3">
10+
<div class="container" id="display">
1211
<a href="blazor-frame.html">View benchmark app ⮕</a>
13-
</p>
14-
12+
</div>
1513
<script type="module" src="benchmarks/index.js"></script>
1614
</body>
1715
</html>

0 commit comments

Comments
 (0)