Skip to content

Add .NET on WebAssembly workload #73

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
109 changes: 109 additions & 0 deletions JetStreamDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,32 @@ class WasmLegacyBenchmark extends Benchmark {
}
};

function dotnetPreloads(type)
{
return {
dotnetUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/dotnet.js`,
dotnetNativeUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/dotnet.native.js`,
dotnetRuntimeUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/dotnet.runtime.js`,
wasmBinaryUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/dotnet.native.wasm`,
icuCustomUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/icudt_CJK.dat`,
dllCollectionsConcurrentUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.Collections.Concurrent.wasm`,
dllCollectionsUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.Collections.wasm`,
dllComponentModelPrimitivesUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.ComponentModel.Primitives.wasm`,
dllComponentModelTypeConverterUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.ComponentModel.TypeConverter.wasm`,
dllDrawingPrimitivesUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.Drawing.Primitives.wasm`,
dllDrawingUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.Drawing.wasm`,
dllIOPipelinesUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.IO.Pipelines.wasm`,
dllLinqUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.Linq.wasm`,
dllMemoryUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.Memory.wasm`,
dllObjectModelUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.ObjectModel.wasm`,
dllPrivateCorelibUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.Private.CoreLib.wasm`,
dllRuntimeInteropServicesJavaScriptUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.Runtime.InteropServices.JavaScript.wasm`,
dllTextEncodingsWebUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.Text.Encodings.Web.wasm`,
dllTextJsonUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.Text.Json.wasm`,
dllAppUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/dotnet.wasm`,
}
}

let BENCHMARKS = [
// ARES
new DefaultBenchmark({
Expand Down Expand Up @@ -2235,6 +2261,89 @@ let BENCHMARKS = [
iterations: 40,
tags: ["Wasm"],
}),
// .NET
new AsyncBenchmark({
name: "dotnet-interp-string",
files: [
"./wasm/dotnet/string.js",
"./wasm/dotnet/benchmark.js",
],
preload: dotnetPreloads("interp"),
iterations: 20,
tags: ["Wasm", "dotnet"]
}),
new AsyncBenchmark({
name: "dotnet-interp-json",
files: [
"./wasm/dotnet/json.js",
"./wasm/dotnet/benchmark.js",
],
preload: dotnetPreloads("interp"),
iterations: 20,
tags: ["Wasm", "dotnet"]
}),
new AsyncBenchmark({
name: "dotnet-interp-exceptions",
files: [
"./wasm/dotnet/exceptions.js",
"./wasm/dotnet/benchmark.js",
],
preload: dotnetPreloads("interp"),
iterations: 10,
tags: ["Wasm", "dotnet"]
}),
new AsyncBenchmark({
name: "dotnet-interp-raytracer",
files: [
"./wasm/dotnet/raytracer.js",
"./wasm/dotnet/benchmark.js",
],
preload: dotnetPreloads("interp"),
iterations: 7,
worstCaseCount: 2,
tags: ["Wasm", "dotnet"]
}),
new AsyncBenchmark({
name: "dotnet-aot-string",
files: [
"./wasm/dotnet/string.js",
"./wasm/dotnet/benchmark.js",
],
preload: dotnetPreloads("aot"),
iterations: 20,
tags: ["Wasm", "dotnet"]
}),
new AsyncBenchmark({
name: "dotnet-aot-json",
files: [
"./wasm/dotnet/json.js",
"./wasm/dotnet/benchmark.js",
],
preload: dotnetPreloads("aot"),
iterations: 20,
tags: ["Wasm", "dotnet"]
}),
new AsyncBenchmark({
name: "dotnet-aot-exceptions",
files: [
"./wasm/dotnet/exceptions.js",
"./wasm/dotnet/benchmark.js",
],
preload: dotnetPreloads("aot"),
iterations: 10,
tags: ["Wasm", "dotnet"]
}),
new AsyncBenchmark({
name: "dotnet-aot-raytracer",
files: [
"./wasm/dotnet/raytracer.js",
"./wasm/dotnet/benchmark.js",
],
preload: dotnetPreloads("aot"),
iterations: 7,
worstCaseCount: 2,
tags: ["Wasm", "dotnet"]
}),
];

// LuaJSFight tests
Expand Down
48 changes: 48 additions & 0 deletions in-depth.html
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,54 @@ <h3>
Source code: <a href="proxy/vue-benchmark.js">vue-benchmark.js</a>
</dd>

<dt id="dotnet-interp-string">dotnet-interp-string</dt>
<dd>
Tests <a href="https://github.com/dotnet/runtime">.NET on WebAssembly</a>. This benchmark tests operations
on .NET implementation of String using Mono Interpreter. Source code: <a href="wasm/dotnet">.NET</a>.
</dd>

<dt id="dotnet-interp-json">dotnet-interp-json</dt>
<dd>
Tests <a href="https://github.com/dotnet/runtime">.NET on WebAssembly</a>. This benchmark tests operations
on .NET implementation of JSON serialization &amp; deserialization using Mono Interpreter. Source code: <a href="wasm/dotnet">.NET</a>.
</dd>

<dt id="dotnet-interp-exceptions">dotnet-interp-exceptions</dt>
<dd>
Tests <a href="https://github.com/dotnet/runtime">.NET on WebAssembly</a>. This benchmark tests operations
on .NET implementation of exception handling using Mono Interpreter. Source code: <a href="wasm/dotnet">.NET</a>.
</dd>

<dt id="dotnet-interp-raytracer">dotnet-interp-raytracer</dt>
<dd>
Tests <a href="https://github.com/dotnet/runtime">.NET on WebAssembly</a>. This benchmark tests computation
of a 3D scene using Mono Interpreter. Source code: <a href="wasm/dotnet">.NET</a>.
</dd>

<dt id="dotnet-aot-string">dotnet-aot-string</dt>
<dd>
Tests <a href="https://github.com/dotnet/runtime">.NET on WebAssembly</a>. This benchmark tests operations
on .NET implementation of String using Mono AOT. Source code: <a href="wasm/dotnet">.NET</a>.
</dd>

<dt id="dotnet-aot-json">dotnet-aot-json</dt>
<dd>
Tests <a href="https://github.com/dotnet/runtime">.NET on WebAssembly</a>. This benchmark tests operations
on .NET implementation of JSON serialization &amp; deserialization using Mono AOT. Source code: <a href="wasm/dotnet">.NET</a>.
</dd>

<dt id="dotnet-aot-exceptions">dotnet-aot-exceptions</dt>
<dd>
Tests <a href="https://github.com/dotnet/runtime">.NET on WebAssembly</a>. This benchmark tests operations
on .NET implementation of exception handling using Mono AOT. Source code: <a href="wasm/dotnet">.NET</a>.
</dd>

<dt id="dotnet-aot-raytracer">dotnet-aot-raytracer</dt>
<dd>
Tests <a href="https://github.com/dotnet/runtime">.NET on WebAssembly</a>. This benchmark tests computation
of a 3D scene using Mono AOT. Source code: <a href="wasm/dotnet">.NET</a>.
</dd>

</dl>

<p><a href="index.html" class="button">&larr; Return to Tests</a></p>
Expand Down
5 changes: 5 additions & 0 deletions wasm/dotnet/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.binlog
.dotnet
.nuget
bin
obj
146 changes: 146 additions & 0 deletions wasm/dotnet/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
class Benchmark {
async init() {
async function fetchBin(name) {
return new Uint8Array(await (await fetch(name)).arrayBuffer());
}

const config = {
mainAssemblyName: "dotnet.dll",
globalizationMode: "custom",
assets: [
{
name: "dotnet.runtime.js",
resolvedUrl: dotnetRuntimeUrl,
moduleExports: await import(dotnetRuntimeUrl),
behavior: "js-module-runtime"
},
{
name: "dotnet.native.js",
resolvedUrl: dotnetNativeUrl,
moduleExports: await import(dotnetNativeUrl),
behavior: "js-module-native"
},
{
name: "dotnet.native.wasm",
resolvedUrl: wasmBinaryUrl,
buffer: await fetchBin(wasmBinaryUrl),
behavior: "dotnetwasm"
},
{
name: "icudt_CJK.dat",
resolvedUrl: icuCustomUrl,
buffer: await fetchBin(icuCustomUrl),
behavior: "icu"
},
{
name: "System.Collections.Concurrent.wasm",
resolvedUrl: dllCollectionsConcurrentUrl,
buffer: await fetchBin(dllCollectionsConcurrentUrl),
behavior: "assembly"
},
{
name: "System.Collections.wasm",
resolvedUrl: dllCollectionsUrl,
buffer: await fetchBin(dllCollectionsUrl),
behavior: "assembly"
},
{
name: "System.ComponentModel.Primitives.wasm",
resolvedUrl: dllComponentModelPrimitivesUrl,
buffer: await fetchBin(dllComponentModelPrimitivesUrl),
behavior: "assembly"
},
{
name: "System.ComponentModel.TypeConverter.wasm",
resolvedUrl: dllComponentModelTypeConverterUrl,
buffer: await fetchBin(dllComponentModelTypeConverterUrl),
behavior: "assembly"
},
{
name: "System.Drawing.Primitives.wasm",
resolvedUrl: dllDrawingPrimitivesUrl,
buffer: await fetchBin(dllDrawingPrimitivesUrl),
behavior: "assembly"
},
{
name: "System.Drawing.wasm",
resolvedUrl: dllDrawingUrl,
buffer: await fetchBin(dllDrawingUrl),
behavior: "assembly"
},
{
name: "System.IO.Pipelines.wasm",
resolvedUrl: dllIOPipelinesUrl,
buffer: await fetchBin(dllIOPipelinesUrl),
behavior: "assembly"
},
{
name: "System.Linq.wasm",
resolvedUrl: dllLinqUrl,
buffer: await fetchBin(dllLinqUrl),
behavior: "assembly"
},
{
name: "System.Memory.wasm",
resolvedUrl: dllMemoryUrl,
buffer: await fetchBin(dllMemoryUrl),
behavior: "assembly"
},
{
name: "System.ObjectModel.wasm",
resolvedUrl: dllObjectModelUrl,
buffer: await fetchBin(dllObjectModelUrl),
behavior: "assembly"
},
{
name: "System.Private.CoreLib.wasm",
resolvedUrl: dllPrivateCorelibUrl,
buffer: await fetchBin(dllPrivateCorelibUrl),
behavior: "assembly"
},
{
name: "System.Runtime.InteropServices.JavaScript.wasm",
resolvedUrl: dllRuntimeInteropServicesJavaScriptUrl,
buffer: await fetchBin(dllRuntimeInteropServicesJavaScriptUrl),
behavior: "assembly"
},
{
name: "System.Text.Encodings.Web.wasm",
resolvedUrl: dllTextEncodingsWebUrl,
buffer: await fetchBin(dllTextEncodingsWebUrl),
behavior: "assembly"
},
{
name: "System.Text.Json.wasm",
resolvedUrl: dllTextJsonUrl,
buffer: await fetchBin(dllTextJsonUrl),
behavior: "assembly"
},
{
name: "dotnet.wasm",
resolvedUrl: dllAppUrl,
buffer: await fetchBin(dllAppUrl),
behavior: "assembly"
}
]
};

this.dotnet = (await import(dotnetUrl)).dotnet;
this.api = await this.dotnet.withModuleConfig({ locateFile: e => e }).withConfig(config).create();
this.exports = await this.api.getAssemblyExports("dotnet.dll");

if (globalThis.dotnetBenchmarkName == "traytracer") {
this.exports.MainJS.PrepareToRender(320, 240, globalThis.navigator.hardwareConcurrency);
await this.exports.MainJS.Render(true);
} else {
await this.exports.BenchInterop.PrepareTask(globalThis.dotnetBenchmarkName);
}
}
async runIteration() {
if (globalThis.dotnetBenchmarkName == "traytracer") {
await this.exports.MainJS.Render(false);
} else {
await this.exports.BenchInterop.Run();
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions wasm/dotnet/build-aot/wwwroot/_framework/dotnet.js

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions wasm/dotnet/build-aot/wwwroot/_framework/dotnet.native.js

Large diffs are not rendered by default.

Binary file not shown.
4 changes: 4 additions & 0 deletions wasm/dotnet/build-aot/wwwroot/_framework/dotnet.runtime.js

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions wasm/dotnet/build-interp/wwwroot/_framework/dotnet.js

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions wasm/dotnet/build-interp/wwwroot/_framework/dotnet.native.js

Large diffs are not rendered by default.

Binary file not shown.
4 changes: 4 additions & 0 deletions wasm/dotnet/build-interp/wwwroot/_framework/dotnet.runtime.js

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions wasm/dotnet/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Download .NET SDK 9.0.300
# Install workload wasm-tools
dotnet publish -o ./build-interp ./src/dotnet/dotnet.csproj
dotnet publish -o ./build-aot ./src/dotnet/dotnet.csproj -p:RunAOTCompilation=true
1 change: 1 addition & 0 deletions wasm/dotnet/exceptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
globalThis.dotnetBenchmarkName = "ExceptionsTask";
1 change: 1 addition & 0 deletions wasm/dotnet/json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
globalThis.dotnetBenchmarkName = "JsonTask";
1 change: 1 addition & 0 deletions wasm/dotnet/raytracer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
globalThis.dotnetBenchmarkName = "traytracer";
Loading