Skip to content

Commit 20e2ee7

Browse files
authored
Docs for SummaryStyle (#2510)
* Added SummaryStyle doc and sample * Fixed link to source code * correct spelling
1 parent 01d9b78 commit 20e2ee7

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
uid: BenchmarkDotNet.SummaryStyle
3+
---
4+
5+
## SummaryStyle in BenchmarkDotNet
6+
7+
`SummaryStyle` is a class in BenchmarkDotNet that allows customization of the summary reports of benchmark results. It offers several properties to fine-tune how the results are displayed.
8+
9+
### Usage
10+
11+
You can customize the summary report by specifying various properties of `SummaryStyle`. These properties include formatting options like whether to print units in the header or content, setting the maximum width for parameter columns, and choosing units for size and time measurements.
12+
13+
### Source Code
14+
15+
[!code-csharp[IntroSummaryStyle.cs](../../../samples/BenchmarkDotNet.Samples/IntroSummaryStyle.cs)]
16+
17+
### Properties
18+
19+
- `PrintUnitsInHeader`: Boolean to indicate if units should be printed in the header.
20+
- `PrintUnitsInContent`: Boolean to control unit printing in the content.
21+
- `PrintZeroValuesInContent`: Determines if zero values should be printed.
22+
- `MaxParameterColumnWidth`: Integer defining the max width for parameter columns.
23+
- `SizeUnit`: Optional `SizeUnit` to specify the unit for size measurements.
24+
- `TimeUnit`: Optional `TimeUnit` for time measurement units.
25+
- `CultureInfo`: `CultureInfo` to define culture-specific formatting.
26+
27+
### Example Output
28+
29+
Using SummaryStyle options:
30+
31+
```markdown
32+
| Method | N | Mean [ns] | Error [ns] | StdDev [ns] |
33+
|------- |---- |--------------:|-----------:|------------:|
34+
| Sleep | 10 | 15,644,973.1 | 32,808.7 | 30,689.3 |
35+
| Sleep | 100 | 109,440,686.7 | 236,673.8 | 221,384.8 |
36+
```
37+
38+
Default:
39+
40+
```markdown
41+
| Method | N | Mean | Error | StdDev |
42+
|------- |---- |----------:|---------:|---------:|
43+
| Sleep | 10 | 15.65 ms | 0.039 ms | 0.034 ms |
44+
| Sleep | 100 | 109.20 ms | 0.442 ms | 0.392 ms |
45+
```
46+
47+
### Links
48+
49+
* @docs.SummaryStyle
50+
* The permanent link to this sample: @BenchmarkDotNet.Samples.IntroSummaryStyle
51+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.Globalization;
2+
using BenchmarkDotNet.Attributes;
3+
using BenchmarkDotNet.Configs;
4+
using BenchmarkDotNet.Reports;
5+
using BenchmarkDotNet.Columns;
6+
using Perfolizer.Horology;
7+
8+
namespace BenchmarkDotNet.Samples
9+
{
10+
[Config(typeof(Config))]
11+
public class IntroSummaryStyle
12+
{
13+
private class Config : ManualConfig
14+
{
15+
public Config()
16+
{
17+
// Configure the summary style here
18+
var summaryStyle = new SummaryStyle
19+
(
20+
cultureInfo: CultureInfo.InvariantCulture,
21+
printUnitsInHeader: true,
22+
printUnitsInContent: false,
23+
sizeUnit: SizeUnit.KB,
24+
timeUnit: TimeUnit.Nanosecond,
25+
maxParameterColumnWidth: 20
26+
27+
);
28+
29+
WithSummaryStyle(summaryStyle);
30+
}
31+
}
32+
33+
[Params(10, 100)]
34+
public int N;
35+
36+
[Benchmark]
37+
public void Sleep() => System.Threading.Thread.Sleep(N);
38+
}
39+
}

0 commit comments

Comments
 (0)