Skip to content

Commit cdeaf45

Browse files
committed
Add a scenario for measuring navigating between components
1 parent 2ca2a2d commit cdeaf45

File tree

5 files changed

+72
-3
lines changed

5 files changed

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

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/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() {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { HtmlUI } from './lib/minibench/minibench.ui.js';
33
import './renderListStress.js';
44
import './jsonHandlingStress.js';
55
import './orgChartStress.js';
6+
import './timerStress.js';
67

78
import { BlazorStressApp } from './util/BlazorStressApp.js';
89

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
// Timers tend to make for good stress scenarios in helping identify memory leaks / use-after-dispose etc.
16+
// While benchmarking it isn't super useful, we'll use it to keep with the theme.
17+
benchmark('Timer', () =>
18+
benchmarkNavigation(app), {
19+
descriptor: {
20+
name: 'blazorwasm/timer',
21+
description: 'Timers - Time in ms'
22+
}
23+
});
24+
});
25+
26+
async function benchmarkNavigation(app) {
27+
for (let i = 0; i < 3; i++) {
28+
const nextCompletion = receiveEvent('Finished updating color');
29+
app.navigateTo('timer');
30+
await nextCompletion;
31+
}
32+
}

0 commit comments

Comments
 (0)