Skip to content

Commit 7dc176d

Browse files
committed
Add basic blazor-wasm benchmark application
1 parent 92631bf commit 7dc176d

File tree

11 files changed

+310
-1
lines changed

11 files changed

+310
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist/
2+
obj/
3+
bin/
4+
.vs/
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "js-framework-benchmark-blazor-wasm",
3+
"version": "1.0.0",
4+
"description": "Blazor WebAssembly demo",
5+
"js-framework-benchmark": {
6+
"frameworkVersion": "3.1.0-preview4.19579.2",
7+
"customURL": "/dist/wwwroot/"
8+
},
9+
"scripts": {
10+
"build-dev": "dotnet build .\\src\\ -c Debug",
11+
"build-prod": "dotnet publish .\\src\\ -c Release -o .\\dist"
12+
},
13+
"keywords": [
14+
"blazor",
15+
"webassembly"
16+
],
17+
"author": "Stefan Krause",
18+
"license": "Apache-2.0",
19+
"homepage": "https://github.com/krausest/js-framework-benchmark",
20+
"repository": {
21+
"type": "git",
22+
"url": "https://github.com/krausest/js-framework-benchmark.git"
23+
}
24+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
@namespace blazor_wasm
2+
3+
<div class="container">
4+
<div class="jumbotron">
5+
<div class="row">
6+
<div class="col-md-6">
7+
<h1>Blazor-WASM-"keyed"</h1>
8+
</div>
9+
<div class="col-md-6">
10+
<div class="row">
11+
<div class="col-sm-6 smallpad">
12+
<button type='button' class='btn btn-primary btn-block' id='run' @onclick="run">Create 1,000 rows</button>
13+
</div>
14+
<div class="col-sm-6 smallpad">
15+
<button type='button' class='btn btn-primary btn-block' id='runlots' @onclick="runlots">Create 10,000 rows</button>
16+
</div>
17+
<div class="col-sm-6 smallpad">
18+
<button type='button' class='btn btn-primary btn-block' id='add' @onclick="add">Append 1,000 rows</button>
19+
</div>
20+
<div class="col-sm-6 smallpad">
21+
<button type='button' class='btn btn-primary btn-block' id='update' @onclick="update">Update every 10th row</button>
22+
</div>
23+
<div class="col-sm-6 smallpad">
24+
<button type='button' class='btn btn-primary btn-block' id='clear' @onclick="clear">Clear</button>
25+
</div>
26+
<div class="col-sm-6 smallpad">
27+
<button type='button' class='btn btn-primary btn-block' id='swaprows' @onclick="swaprows">Swap Rows</button>
28+
</div>
29+
</div>
30+
</div>
31+
</div>
32+
</div>
33+
<table class="table table-hover table-striped test-data">
34+
<tbody id="tbody">
35+
@foreach (var item in data)
36+
{
37+
<tr class="@((item.Id == selected ? "danger" : ""))">
38+
<td class="col-md-1">@item.Id</td>
39+
<td class="col-md-4">
40+
<a href="#" @onclick="(_ => select(item))" @onclick:preventDefault>
41+
@item.Label
42+
</a>
43+
</td>
44+
<td class="col-md-1">
45+
<a href="#" @onclick="(_ => delete(item))" @onclick:preventDefault>
46+
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
47+
</a>
48+
</td>
49+
<td class="col-md-6"></td>
50+
</tr>
51+
}
52+
</tbody>
53+
</table>
54+
<span class="preloadicon glyphicon glyphicon-remove" aria-hidden="true"></span>
55+
</div>
56+
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
5+
namespace blazor_wasm
6+
{
7+
public partial class App
8+
{
9+
int startTime;
10+
string lastMeasure;
11+
Stopwatch Stopwatch;
12+
13+
void startMeasure(string name)
14+
{
15+
Stopwatch = Stopwatch.StartNew();
16+
lastMeasure = name;
17+
}
18+
19+
void stopMeasure()
20+
{
21+
Stopwatch.Stop();
22+
var last = this.lastMeasure ?? "";
23+
if (!string.IsNullOrWhiteSpace(this.lastMeasure))
24+
{
25+
lastMeasure = string.Empty;
26+
Console.WriteLine($"{last} took {Stopwatch.ElapsedMilliseconds} ms");
27+
Stopwatch.Reset();
28+
}
29+
}
30+
31+
List<Data> data = new List<Data>();
32+
int selected;
33+
int id = 1;
34+
Random random = new Random(0);
35+
36+
string[] adjectives = new string[]
37+
{
38+
"pretty", "large", "big", "small", "tall", "short", "long", "handsome", "plain", "quaint", "clean", "elegant", "easy", "angry", "crazy", "helpful", "mushy", "odd", "unsightly", "adorable", "important", "inexpensive", "cheap", "expensive", "fancy"
39+
};
40+
41+
string[] colours = new string[]
42+
{
43+
"red", "yellow", "blue", "green", "pink", "brown", "purple", "brown", "white", "black", "orange"
44+
};
45+
46+
string[] nouns = new string[]
47+
{
48+
"table", "chair", "house", "bbq", "desk", "car", "pony", "cookie", "sandwich", "burger", "pizza", "mouse", "keyboard"
49+
};
50+
51+
List<Data> buildData(int count = 1000)
52+
{
53+
var result = new List<Data>();
54+
for (int i = 0; i < count; i++)
55+
{
56+
result.Add(new Data
57+
{
58+
Id = this.id++,
59+
Label = adjectives[this.random.Next(adjectives.Length)] + " " + colours[this.random.Next(colours.Length)] + " " + nouns[this.random.Next(nouns.Length)]
60+
});
61+
}
62+
63+
return result;
64+
}
65+
66+
public void select(Data item)
67+
{
68+
startMeasure("select");
69+
this.selected = item.Id;
70+
}
71+
72+
void delete(Data item)
73+
{
74+
startMeasure("delete");
75+
this.data.Remove(item);
76+
}
77+
78+
void run()
79+
{
80+
startMeasure("run");
81+
this.data = this.buildData();
82+
}
83+
void runlots()
84+
{
85+
startMeasure("runlots");
86+
this.data = this.buildData(10000);
87+
}
88+
void add()
89+
{
90+
startMeasure("add");
91+
this.data.AddRange(this.buildData(1000));
92+
}
93+
void update()
94+
{
95+
startMeasure("update");
96+
for (var i = 0; i < this.data.Count; i += 10)
97+
{
98+
this.data[i].Label += " !!!";
99+
}
100+
}
101+
void clear()
102+
{
103+
startMeasure("clear");
104+
this.data = new List<Data>();
105+
this.selected = 0;
106+
}
107+
void swaprows()
108+
{
109+
startMeasure("swapRows");
110+
if (this.data.Count > 998)
111+
{
112+
var a = this.data[1];
113+
this.data[1] = this.data[998];
114+
this.data[998] = a;
115+
}
116+
}
117+
118+
protected override void OnAfterRender(bool firstRender)
119+
{
120+
if (!firstRender)
121+
{
122+
this.stopMeasure();
123+
}
124+
}
125+
}
126+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace blazor_wasm
2+
{
3+
public class Data
4+
{
5+
public int Id { get; set; }
6+
public string Label { get; set; }
7+
}
8+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Threading.Tasks;
2+
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
3+
4+
namespace blazor_wasm
5+
{
6+
public class Program
7+
{
8+
public static async Task Main(string[] args)
9+
{
10+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
11+
builder.RootComponents.Add<App>("app");
12+
13+
await builder.Build().RunAsync();
14+
}
15+
}
16+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:33030",
7+
"sslPort": 44363
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
15+
"environmentVariables": {
16+
"ASPNETCORE_ENVIRONMENT": "Development"
17+
}
18+
},
19+
"blazor-wasm": {
20+
"commandName": "Project",
21+
"launchBrowser": true,
22+
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
23+
"applicationUrl": "https://localhost:5001;http://localhost:5000",
24+
"environmentVariables": {
25+
"ASPNETCORE_ENVIRONMENT": "Development"
26+
}
27+
}
28+
}
29+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@using System.Net.Http
2+
@using System.Net.Http.Json
3+
@using Microsoft.AspNetCore.Components.Forms
4+
@using Microsoft.AspNetCore.Components.Routing
5+
@using Microsoft.AspNetCore.Components.Web
6+
@using Microsoft.JSInterop
7+
@using blazor_wasm
8+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.1</TargetFramework>
5+
<RazorLangVersion>3.0</RazorLangVersion>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.0-preview4.20210.8" />
10+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.0-preview4.20210.8" PrivateAssets="all" />
11+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.0-preview4.20210.8" PrivateAssets="all" />
12+
<PackageReference Include="System.Net.Http.Json" Version="3.2.0-preview5.20210.3" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta charset="utf-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
7+
<title>blazor-wasm</title>
8+
<base href="" />
9+
<link href="/css/currentStyle.css" rel="stylesheet"/>
10+
</head>
11+
12+
<body>
13+
<app>Loading...</app>
14+
15+
<div id="blazor-error-ui">
16+
An unhandled error has occurred.
17+
<a href="" class="reload">Reload</a>
18+
<a class="dismiss">🗙</a>
19+
</div>
20+
<script src="_framework/blazor.webassembly.js"></script>
21+
</body>
22+
23+
</html>

0 commit comments

Comments
 (0)