Skip to content
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
10 changes: 7 additions & 3 deletions docs/articles/samples/IntroWasm.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ uid: BenchmarkDotNet.Samples.IntroWasm

## Sample: IntroWasm

WasmToolchain uses a local Mono Runtime build to run the benchmarks compiled as WebAssembly using V8 JavaScript Engine.
`WasmToolchain` builds benchmarks as WebAssembly and runs them under a JavaScript engine (V8 by default).

It is supported only on Unix.

If you hit `NETSDK1147` (missing workload), install the required workload (for example: `dotnet workload install wasm-tools`).

### Source code

[!code-csharp[IntroInProcess.cs](../../../samples/BenchmarkDotNet.Samples/IntroWasm.cs)]
[!code-csharp[IntroWasm.cs](../../../samples/BenchmarkDotNet.Samples/IntroWasm.cs)]

### Links

* @docs.toolchains
* The permanent link to this sample: @BenchmarkDotNet.Samples.IntroWasm

---
---
26 changes: 13 additions & 13 deletions samples/BenchmarkDotNet.Samples/IntroWasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Toolchains;
using BenchmarkDotNet.Toolchains.DotNetCli;
using BenchmarkDotNet.Toolchains.MonoWasm;

Expand All @@ -12,11 +11,12 @@ namespace BenchmarkDotNet.Samples
// *** Command Line Arguments ***
public class IntroWasmCmdConfig
{
// the args must contain:
// an information that we want to run benchmark as Wasm:
// --runtimes Wasm
// path to dotnet cli
// --cli /home/adam/projects/runtime/dotnet.sh
// Example:
// --runtimes wasmnet8.0
// --cli /path/to/dotnet (optional)
// --wasmEngine v8 (optional)
// --wasmArgs "--expose_wasm" (optional)
// --wasmDataDir /path/to/data (optional)
public static void Run(string[] args) => BenchmarkSwitcher.FromAssembly(typeof(IntroWasmCmdConfig).Assembly).Run(args);

[Benchmark]
Expand All @@ -31,16 +31,16 @@ public class IntroWasmFluentConfig
{
public static void Run()
{
// the Wasm Toolchain requires two mandatory arguments:
const string cliPath = @"/home/adam/projects/runtime/dotnet.sh";
// Optional: set this to use a custom `dotnet` (for example, a local dotnet/runtime build).
const string cliPath = "";

WasmRuntime runtime = new WasmRuntime(msBuildMoniker: "net5.0");
var runtime = new WasmRuntime();
NetCoreAppSettings netCoreAppSettings = new NetCoreAppSettings(
targetFrameworkMoniker: "net5.0", runtimeFrameworkVersion: "", name: "Wasm",
targetFrameworkMoniker: runtime.MsBuildMoniker, runtimeFrameworkVersion: "", name: runtime.Name,
customDotNetCliPath: cliPath);
IToolchain toolChain = WasmToolchain.From(netCoreAppSettings);
var toolChain = WasmToolchain.From(netCoreAppSettings);

BenchmarkRunner.Run<IntroCustomMonoFluentConfig>(DefaultConfig.Instance
BenchmarkRunner.Run<IntroWasmFluentConfig>(DefaultConfig.Instance
.AddJob(Job.ShortRun.WithRuntime(runtime).WithToolchain(toolChain)));
}

Expand All @@ -50,4 +50,4 @@ public void Foo()
// Benchmark body
}
}
}
}
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/ConsoleArguments/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public bool UseDisassemblyDiagnoser
[Option("AOTCompilerPath", Required = false, HelpText = "Path to Mono AOT compiler, used for MonoAotLLVM.")]
public FileInfo? AOTCompilerPath { get; set; }

[Option("AOTCompilerMode", Required = false, Default = MonoAotCompilerMode.mini, HelpText = "Mono AOT compiler mode, either 'mini' or 'llvm'")]
[Option("AOTCompilerMode", Required = false, Default = MonoAotCompilerMode.mini, HelpText = "Mono AOT compiler mode, either 'mini', 'llvm', or 'wasm'")]
public MonoAotCompilerMode AOTCompilerMode { get; set; }

[Option("wasmDataDir", Required = false, HelpText = "Wasm data directory")]
Expand Down