Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* BenchmarkDotNet as global tool This resolves #213. * Set TargetFramework to "netcoreapp2.1" * Add import for common build properties. * Docs: BenchmarkDotNet as global dotnet tool
- Loading branch information
1 parent
2869966
commit 923b23c
Showing
8 changed files
with
195 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
uid: docs.dotnet-benchmarkdotnet | ||
name: The global BenchmarkDotNet tool | ||
--- | ||
|
||
# BenchmarkDotNet as global dotnet tool | ||
|
||
BenchmarkDotNet is also available as a global dotnet tool and provides a convenient way to execute your benchmark(s) from the command line interface. | ||
|
||
## How to install the tool | ||
|
||
Download and install the [.NET Core 2.1 SDK](https://www.microsoft.com/net/download) or newer. Once installed, run the following command: | ||
|
||
```log | ||
dotnet tool install BenchmarkDotNet.Tool -g | ||
``` | ||
|
||
If you already have a previous version of installed, you can upgrade to the latest version using the following command: | ||
|
||
```log | ||
dotnet tool update BenchmarkDotNet.Tool -g | ||
``` | ||
|
||
## Usage | ||
|
||
The basic usage syntax is: | ||
|
||
```log | ||
dotnet benchmarkdotnet [arguments] [options] | ||
``` | ||
|
||
### Arguments | ||
|
||
* The **first** argument in `[arguments]` **must** be the path to an assembly file with your benchmarks. | ||
* Further arguments are passed to the the `BenchmarkSwitcher`. | ||
|
||
### Options | ||
|
||
| Option | Description | | ||
| ------ | ----------- | | ||
|--version|Show version information| | ||
|-?, -h or --help|Show help information| | ||
|
||
```log | ||
dotnet benchmarkdotnet -? | ||
``` | ||
|
||
**Note**: This shows also all valid arguments for `BenchmarkSwitcher`. | ||
|
||
## Examples | ||
|
||
The following example scans the `MyAssemblyWithBenchmarks.dll` for benchmarks and lets you select which benchmark(s) to execute: | ||
|
||
```log | ||
dotnet benchmarkdotnet MyAssemblyWithBenchmarks.dll | ||
``` | ||
|
||
To execute all benchmarks use `--filter *`: | ||
|
||
```log | ||
dotnet benchmarkdotnet MyAssemblyWithBenchmarks.dll --filter * | ||
``` | ||
|
||
**Note**: For further arguments for the `BenchmarkSwticher` see also [Console Arguments](console-args.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Import Project="..\..\build\common.props" /> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
<IsPackable>true</IsPackable> | ||
<PackAsTool>true</PackAsTool> | ||
<ToolCommandName>dotnet-BenchmarkDotNet</ToolCommandName> | ||
<Description>A dotnet tool to execute BenchmarkDotNet benchmarks.</Description> | ||
<PackageTags>benchmark;benchmarking;performance;tool</PackageTags> | ||
<PackageId>BenchmarkDotNetTool</PackageId> | ||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\BenchmarkDotNet\BenchmarkDotNet.csproj" /> | ||
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="2.3.0" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using BenchmarkDotNet.ConsoleArguments; | ||
using BenchmarkDotNet.Running; | ||
using CommandLine; | ||
using McMaster.Extensions.CommandLineUtils; | ||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Text; | ||
|
||
namespace BenchmarkDotNet.Tool | ||
{ | ||
[Command( | ||
Name = "BenchmarkDotNet", | ||
Description = "A dotnet tool to execute benchmarks built with BenchmarkDotNet.")] | ||
[HelpOption()] | ||
[VersionOptionFromMember(MemberName = nameof(GetVersion))] | ||
public sealed class Program | ||
{ | ||
public static int Main(string[] args) | ||
{ | ||
using (CommandLineApplication<Program> app = new CommandLineApplication<Program>()) | ||
{ | ||
app.Conventions.UseDefaultConventions(); | ||
app.ThrowOnUnexpectedArgument = false; | ||
app.ExtendedHelpText = GenerateExtendedHelpText(); | ||
return app.Execute(args); | ||
} | ||
} | ||
|
||
private IConsole Console => PhysicalConsole.Singleton; | ||
|
||
[Argument(0, Description = "The assembly with the benchmarks (required).")] | ||
[Required] | ||
[FileExists] | ||
public string AssemblyFile { get; set; } | ||
|
||
public string[] RemainingArguments { get; set; } | ||
|
||
public int OnExecute() | ||
{ | ||
Assembly assembly; | ||
try | ||
{ | ||
assembly = Assembly.LoadFrom(AssemblyFile); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.Error.WriteLine($"Couldn't load the assembly {AssemblyFile}."); | ||
Console.Error.WriteLine(ex.ToString()); | ||
return 1; | ||
} | ||
|
||
BenchmarkSwitcher benchmarkSwitcher = BenchmarkSwitcher.FromAssembly(assembly); | ||
benchmarkSwitcher.Run(RemainingArguments); | ||
return 0; | ||
} | ||
|
||
private static string GetVersion() | ||
{ | ||
return typeof(Program).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion; | ||
} | ||
|
||
private static string GenerateExtendedHelpText() | ||
{ | ||
StringBuilder sb = new StringBuilder() | ||
.AppendLine() | ||
.AppendLine("The first argument in [arguments] is the benchmark assembly and every following argument is passed to the BenchmarkSwitcher.") | ||
.AppendLine("BenchmarkSwitcher arguments:") | ||
.AppendLine(); | ||
using (StringWriter sw = new StringWriter(sb)) | ||
{ | ||
using (Parser p = new Parser((ps) => { ps.HelpWriter = sw; })) | ||
{ | ||
p.ParseArguments<CommandLineOptions>(new string[] { "--help" }); | ||
} | ||
} | ||
return sb.ToString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"profiles": { | ||
"BenchmarkDotNet.Tool": { | ||
"commandName": "Project" | ||
} | ||
} | ||
} |