diff --git a/docs/articles/samples/IntroWasm.md b/docs/articles/samples/IntroWasm.md index 8850f837c3..1f42a67c79 100644 --- a/docs/articles/samples/IntroWasm.md +++ b/docs/articles/samples/IntroWasm.md @@ -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 on Windows, Linux, and macOS. + +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 ---- \ No newline at end of file +--- diff --git a/samples/BenchmarkDotNet.Samples/IntroWasm.cs b/samples/BenchmarkDotNet.Samples/IntroWasm.cs index 108c03b022..7cc0445e26 100644 --- a/samples/BenchmarkDotNet.Samples/IntroWasm.cs +++ b/samples/BenchmarkDotNet.Samples/IntroWasm.cs @@ -3,7 +3,6 @@ using BenchmarkDotNet.Environments; using BenchmarkDotNet.Jobs; using BenchmarkDotNet.Running; -using BenchmarkDotNet.Toolchains; using BenchmarkDotNet.Toolchains.DotNetCli; using BenchmarkDotNet.Toolchains.MonoWasm; @@ -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] @@ -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: "net8.0", RuntimeMoniker.WasmNet80, "Wasm .net8.0", false, "v8"); NetCoreAppSettings netCoreAppSettings = new NetCoreAppSettings( targetFrameworkMoniker: "net8.0", runtimeFrameworkVersion: "", name: "Wasm", customDotNetCliPath: cliPath); - IToolchain toolChain = WasmToolchain.From(netCoreAppSettings); + var toolChain = WasmToolchain.From(netCoreAppSettings); - BenchmarkRunner.Run(DefaultConfig.Instance + BenchmarkRunner.Run(DefaultConfig.Instance .AddJob(Job.ShortRun.WithRuntime(runtime).WithToolchain(toolChain))); } diff --git a/src/BenchmarkDotNet/ConsoleArguments/CommandLineOptions.cs b/src/BenchmarkDotNet/ConsoleArguments/CommandLineOptions.cs index 798522c6d9..50bde8a697 100644 --- a/src/BenchmarkDotNet/ConsoleArguments/CommandLineOptions.cs +++ b/src/BenchmarkDotNet/ConsoleArguments/CommandLineOptions.cs @@ -216,7 +216,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("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.")]