diff --git a/docs/articles/samples/IntroWasm.md b/docs/articles/samples/IntroWasm.md index 8850f837c3..cdecb25132 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 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 ---- \ No newline at end of file +--- diff --git a/samples/BenchmarkDotNet.Samples/IntroWasm.cs b/samples/BenchmarkDotNet.Samples/IntroWasm.cs index 29411e37d4..3df7564dd8 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: "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(DefaultConfig.Instance + BenchmarkRunner.Run(DefaultConfig.Instance .AddJob(Job.ShortRun.WithRuntime(runtime).WithToolchain(toolChain))); } @@ -50,4 +50,4 @@ public void Foo() // Benchmark body } } -} \ No newline at end of file +} diff --git a/src/BenchmarkDotNet/ConsoleArguments/CommandLineOptions.cs b/src/BenchmarkDotNet/ConsoleArguments/CommandLineOptions.cs index a494f42d46..f19b4bc2ed 100644 --- a/src/BenchmarkDotNet/ConsoleArguments/CommandLineOptions.cs +++ b/src/BenchmarkDotNet/ConsoleArguments/CommandLineOptions.cs @@ -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")]