Skip to content

Add a scenario with timers #19626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
@page "/timer"
@inject IJSRuntime JSRuntime
@using System.Threading
@implements IDisposable

<h1 style="background-color: rgb(@red, @green, @blue)">Timer component</h1>

@code
{
Random random = new Random();
Timer timer;
int red = 128;
int green = 128;
int blue = 128;

protected override void OnInitialized()
{
timer = new Timer(UpdateColor, null, 0, 100);
}

void UpdateColor(object state)
{
InvokeAsync(() =>
{
red = random.Next(0, 256);
green = random.Next(0, 256);
blue = random.Next(0, 256);
StateHasChanged();
BenchmarkEvent.Send(JSRuntime, "Finished updating color");
});
}

public void Dispose() => timer.Dispose();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
<a href="">Home</a> |
<a href="renderlist">RenderList</a> |
<a href="json">JSON</a> |
<a href="orgchart">OrgChart</a>
<a href="orgchart">OrgChart</a> |
<a href="timer">Timer</a>

<hr/>
<hr />

<div>
@Body
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class HtmlUI {
true
);
this.runButton.style.display = areAllIdle ? 'block' : 'none';
this.stopButton.style.display = areAllIdle ? 'none' : 'block';;
this.stopButton.style.display = areAllIdle ? 'none' : 'block';
}

get globalRunOptions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { HtmlUI } from './lib/minibench/minibench.ui.js';
import './renderListStress.js';
import './jsonHandlingStress.js';
import './orgChartStress.js';
import './timerStress.js';

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { group, benchmark, setup, teardown } from './lib/minibench/minibench.js';
import { BlazorApp } from './util/BlazorApp.js';
import { receiveEvent } from './util/BenchmarkEvents.js';

group('Navigation', () => {
let app;

setup(async () => {
app = new BlazorApp();
await app.start();
});

teardown(() => app.dispose());

// Timers tend to make for good stress scenarios in helping identify memory leaks / use-after-dispose etc.
// While benchmarking it isn't super useful, we'll use it to keep with the theme.
benchmark('Timer', () =>
benchmarkNavigation(app), {
descriptor: {
name: 'blazorwasm/timer',
description: 'Timers - Time in ms'
}
});
});

async function benchmarkNavigation(app) {
for (let i = 0; i < 3; i++) {
const nextCompletion = receiveEvent('Finished updating color');
app.navigateTo('timer');
await nextCompletion;
}
}