Skip to content

Commit 0fa9abd

Browse files
authored
Docs: update IntroWasm sample (#3034)
* docs(wasm): update IntroWasm sample * docs(wasm): update supported platforms note
1 parent 416275c commit 0fa9abd

3 files changed

Lines changed: 18 additions & 14 deletions

File tree

docs/articles/samples/IntroWasm.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@ uid: BenchmarkDotNet.Samples.IntroWasm
44

55
## Sample: IntroWasm
66

7-
WasmToolchain uses a local Mono Runtime build to run the benchmarks compiled as WebAssembly using V8 JavaScript Engine.
7+
`WasmToolchain` builds benchmarks as WebAssembly and runs them under a JavaScript engine (V8 by default).
8+
9+
It is supported on Windows, Linux, and macOS.
10+
11+
If you hit `NETSDK1147` (missing workload), install the required workload (for example: `dotnet workload install wasm-tools`).
812

913
### Source code
1014

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

1317
### Links
1418

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

18-
---
22+
---

samples/BenchmarkDotNet.Samples/IntroWasm.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using BenchmarkDotNet.Environments;
44
using BenchmarkDotNet.Jobs;
55
using BenchmarkDotNet.Running;
6-
using BenchmarkDotNet.Toolchains;
76
using BenchmarkDotNet.Toolchains.DotNetCli;
87
using BenchmarkDotNet.Toolchains.MonoWasm;
98

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

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

3737
WasmRuntime runtime = new WasmRuntime(msBuildMoniker: "net8.0", RuntimeMoniker.WasmNet80, "Wasm .net8.0", false, "v8");
3838
NetCoreAppSettings netCoreAppSettings = new NetCoreAppSettings(
3939
targetFrameworkMoniker: "net8.0", runtimeFrameworkVersion: "", name: "Wasm",
4040
customDotNetCliPath: cliPath);
41-
IToolchain toolChain = WasmToolchain.From(netCoreAppSettings);
41+
var toolChain = WasmToolchain.From(netCoreAppSettings);
4242

43-
BenchmarkRunner.Run<IntroCustomMonoFluentConfig>(DefaultConfig.Instance
43+
BenchmarkRunner.Run<IntroWasmFluentConfig>(DefaultConfig.Instance
4444
.AddJob(Job.ShortRun.WithRuntime(runtime).WithToolchain(toolChain)));
4545
}
4646

src/BenchmarkDotNet/ConsoleArguments/CommandLineOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public bool UseDisassemblyDiagnoser
216216
[Option("AOTCompilerPath", Required = false, HelpText = "Path to Mono AOT compiler, used for MonoAotLLVM.")]
217217
public FileInfo? AOTCompilerPath { get; set; }
218218

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

222222
[Option("wasmRuntimeFlavor", Required = false, Default = Environments.RuntimeFlavor.Mono, HelpText = "Runtime flavor for WASM benchmarks: 'Mono' (default) uses the Mono runtime pack, 'CoreCLR' uses the CoreCLR runtime pack.")]

0 commit comments

Comments
 (0)