Skip to content

Commit 0cf1850

Browse files
authored
Improve getting started guide (#2218)
- Adjust the instructions and examples to reflect more modern .NET - Add a section about how to run the benchmarks (making sure you use Release) - Fix the "Analyze" section, which was misleading, and add more useful information
1 parent ea0eb2f commit 0cf1850

File tree

4 files changed

+130
-145
lines changed

4 files changed

+130
-145
lines changed

docs/articles/guides/getting-started.md

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
# Getting started
2-
32
To get started with BenchmarkDotNet, please follow these steps.
43

54
## Step 1. Create a project
65
Create a new console application.
76

87
## Step 2. Installation
9-
108
Install BenchmarkDotNet via the NuGet package: [BenchmarkDotNet](https://www.nuget.org/packages/BenchmarkDotNet/)
119

12-
```
13-
PM> Install-Package BenchmarkDotNet
10+
```cmd
11+
> dotnet add package BenchmarkDotNet
1412
```
1513

1614
Read more about BenchmarkDotNet NuGet packages: @docs.nuget
@@ -58,39 +56,50 @@ namespace MyBenchmarks
5856
}
5957
```
6058

61-
The `BenchmarkRunner.Run<Md5VsSha256>()` call runs your benchmarks and print results to console output.
59+
The `BenchmarkRunner.Run<Md5VsSha256>()` call runs your benchmarks and prints results to the console.
6260

63-
## Step 4. View results
61+
## Step 4. Run benchmarks
62+
Start your console application to run the benchmarks. The application must be built in the Release configuration.
63+
64+
```cmd
65+
> dotnet run -c Release
66+
```
67+
68+
## Step 5. View results
6469
View the results. Here is an example of output from the above benchmark:
6570

6671
```
67-
BenchmarkDotNet=v0.11.3, OS=Windows 10.0.17134.472 (1803/April2018Update/Redstone4)
68-
Intel Core i7-2630QM CPU 2.00GHz (Sandy Bridge), 1 CPU, 8 logical and 4 physical cores
69-
Frequency=1948699 Hz, Resolution=513.1629 ns, Timer=TSC
70-
.NET Core SDK=2.1.502
71-
[Host] : .NET Core 2.1.6 (CoreCLR 4.6.27019.06, CoreFX 4.6.27019.05), 64bit RyuJIT
72-
DefaultJob : .NET Core 2.1.6 (CoreCLR 4.6.27019.06, CoreFX 4.6.27019.05), 64bit RyuJIT
73-
74-
75-
| Method | Mean | Error | StdDev |
76-
|------- |----------:|----------:|----------:|
77-
| Sha256 | 100.90 us | 0.5070 us | 0.4494 us |
78-
| Md5 | 37.66 us | 0.1290 us | 0.1207 us |
72+
BenchmarkDotNet=v0.13.2, OS=Windows 10 (10.0.19045.2251)
73+
Intel Core i7-4770HQ CPU 2.20GHz (Haswell), 1 CPU, 8 logical and 4 physical cores
74+
.NET SDK=7.0.100
75+
[Host] : .NET 7.0.0 (7.0.22.51805), X64 RyuJIT AVX2
76+
DefaultJob : .NET 7.0.0 (7.0.22.51805), X64 RyuJIT AVX2
77+
78+
79+
| Method | Mean | Error | StdDev |
80+
|------- |---------:|---------:|---------:|
81+
| Sha256 | 51.57 us | 0.311 us | 0.291 us |
82+
| Md5 | 21.91 us | 0.138 us | 0.129 us |
7983
```
8084

85+
## Step 6. Analyze results
86+
BenchmarkDotNet will automatically create basic reports in the `.\BenchmarkDotNet.Artifacts\results` folder that can be shared and analyzed.
8187

82-
## Step 5. Analyze results
88+
To help analyze performance in further depth, you can configure your benchmark to collect and output more detailed information. Benchmark configuration can be conveniently changed by adding attributes to the class containing your benchmarks. For example:
8389

84-
Analyze it. In your bin directory, you can find a lot of useful files with detailed information. For example:
90+
* [Diagnosers](../configs/diagnosers.md)
91+
* GC allocations: `[MemoryDiagnoser]`
92+
* Code size and disassembly: `[DisassemblyDiagnoser]`
93+
* Threading statistics: `[ThreadingDiagnoser]`
94+
* [Exporters](../configs/exporters.md)
95+
* CSV reports with raw data: `[CsvMeasurementsExporter]`
96+
* JSON reports with raw data: `[JsonExporter]`
97+
* Plots (if you have installed R): `[RPlotExporter]`
8598

86-
* Csv reports with raw data: `Md5VsSha256-report.csv`, `Md5VsSha256-runs.csv`
87-
* Markdown reports: `Md5VsSha256-report-default.md`, `Md5VsSha256-report-stackoverflow.md`, `Md5VsSha256-report-github.md`
88-
* Plain report and log: `Md5VsSha256-report.txt`, `Md5VsSha256.log`
89-
* Plots (if you have installed R): `Md5VsSha256-barplot.png`, `Md5VsSha256-boxplot.png`, and so on.
99+
For more information, see [Configs](../configs/configs.md).
90100

91101
## Next steps
92-
93-
BenchmarkDotNet provides a lot of features which help to high-quality performance research.
94-
If you want to know more about BenchmarkDotNet features, checkout the [Overview](../overview.md) page.
95-
If you want have any questions, checkout the [FAQ](../faq.md) page.
96-
If you didn't find answer for your question on this page, [ask it on gitter](https://gitter.im/dotnet/BenchmarkDotNet) or [create an issue](https://github.com/dotnet/BenchmarkDotNet/issues).
102+
BenchmarkDotNet provides features which aid high-quality performance research.
103+
If you want to know more about BenchmarkDotNet features, check out the [Overview](../overview.md) page.
104+
If you have any questions, check out the [FAQ](../faq.md) page.
105+
If you didn't find an answer for your question on this page, [ask it on Gitter](https://gitter.im/dotnet/BenchmarkDotNet) or [create an issue on GitHub](https://github.com/dotnet/BenchmarkDotNet/issues).

docs/articles/guides/how-to-run.md

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,4 @@ Also you can use the config command style to specify some config from command li
3131
dotnet run -c Release -- --job short --runtimes net472 net7.0 --filter *BenchmarkClass1*
3232
```
3333

34-
The most important thing about `BenchmarkSwitcher` is that you need to pass the `args` from `Main` to the `Run` method. If you don't, it won't parse the arguments.
35-
36-
37-
## Url
38-
39-
You can also run a benchmark directly from the internet:
40-
41-
```cs
42-
string url = "<E.g. direct link to raw content of a gist>";
43-
var summary = BenchmarkRunner.RunUrl(url);
44-
```
45-
46-
**Note:** it works only for Full .NET Framework. It's not recommended to use this approach.
47-
48-
## Source
49-
50-
```cs
51-
string benchmarkSource = "public class MyBenchmarkClass { ...";
52-
var summary = BenchmarkRunner.RunSource(benchmarkSource);
53-
```
54-
55-
**Note:** it works only for Full .NET Framework. It's not recommended to use this approach.
34+
The most important thing about `BenchmarkSwitcher` is that you need to pass the `args` from `Main` to the `Run` method. If you don't, it won't parse the arguments.

0 commit comments

Comments
 (0)