From 4f79f66f14a5204e0d269100e07b981aacba121a Mon Sep 17 00:00:00 2001 From: Matt Chaulklin Date: Tue, 23 Jan 2024 11:05:47 -0500 Subject: [PATCH 1/3] Added SummaryStyle doc and sample --- docs/articles/samples/IntroSummaryStyle.md | 51 +++++++++++++++++++ .../IntroSummaryStyle.cs | 39 ++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 docs/articles/samples/IntroSummaryStyle.md create mode 100644 samples/BenchmarkDotNet.Samples/IntroSummaryStyle.cs diff --git a/docs/articles/samples/IntroSummaryStyle.md b/docs/articles/samples/IntroSummaryStyle.md new file mode 100644 index 0000000000..0214bbd2be --- /dev/null +++ b/docs/articles/samples/IntroSummaryStyle.md @@ -0,0 +1,51 @@ +--- +uid: BenchmarkDotNet.SummaryStyle +--- + +## SummaryStyle in BenchmarkDotNet + +`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. + +### Usage + +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. + +### Source Code + +[!code-csharp[SummaryStyle.cs](../../../samples/BenchmarkDotNet.Samples/IntroSummaryStyle.cs)] + +### Properties + +- `PrintUnitsInHeader`: Boolean to indicate if units should be printed in the header. +- `PrintUnitsInContent`: Boolean to control unit printing in the content. +- `PrintZeroValuesInContent`: Determines if zero values should be printed. +- `MaxParameterColumnWidth`: Integer defining the max width for parameter columns. +- `SizeUnit`: Optional `SizeUnit` to specify the unit for size measurements. +- `TimeUnit`: Optional `TimeUnit` for time measurement units. +- `CultureInfo`: `CultureInfo` to define culture-specific formatting. + +### Example Output + +Using SummarySyle options: + +```markdown +| Method | N | Mean [ns] | Error [ns] | StdDev [ns] | +|------- |---- |--------------:|-----------:|------------:| +| Sleep | 10 | 15,644,973.1 | 32,808.7 | 30,689.3 | +| Sleep | 100 | 109,440,686.7 | 236,673.8 | 221,384.8 | +``` + +Default: + +```markdown +| Method | N | Mean | Error | StdDev | +|------- |---- |----------:|---------:|---------:| +| Sleep | 10 | 15.65 ms | 0.039 ms | 0.034 ms | +| Sleep | 100 | 109.20 ms | 0.442 ms | 0.392 ms | +``` + +### Links + +* @docs.summarystyle +* The permanent link to this sample: @BenchmarkDotNet.Samples.IntroSummaryStyle + diff --git a/samples/BenchmarkDotNet.Samples/IntroSummaryStyle.cs b/samples/BenchmarkDotNet.Samples/IntroSummaryStyle.cs new file mode 100644 index 0000000000..e24fda60e4 --- /dev/null +++ b/samples/BenchmarkDotNet.Samples/IntroSummaryStyle.cs @@ -0,0 +1,39 @@ +using System.Globalization; +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Reports; +using BenchmarkDotNet.Columns; +using Perfolizer.Horology; + +namespace BenchmarkDotNet.Samples +{ + [Config(typeof(Config))] + public class IntroSummaryStyle + { + private class Config : ManualConfig + { + public Config() + { + // Configure the summary style here + var summaryStyle = new SummaryStyle + ( + cultureInfo: CultureInfo.InvariantCulture, + printUnitsInHeader: true, + printUnitsInContent: false, + sizeUnit: SizeUnit.KB, + timeUnit: TimeUnit.Nanosecond, + maxParameterColumnWidth: 20 + + ); + + WithSummaryStyle(summaryStyle); + } + } + + [Params(10, 100)] + public int N; + + [Benchmark] + public void Sleep() => System.Threading.Thread.Sleep(N); + } +} \ No newline at end of file From ede1190a4cea6c8368b3fcd3421f36bfa362868e Mon Sep 17 00:00:00 2001 From: Matt Chaulklin Date: Tue, 23 Jan 2024 11:09:19 -0500 Subject: [PATCH 2/3] Fixed link to source code --- docs/articles/samples/IntroSummaryStyle.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/articles/samples/IntroSummaryStyle.md b/docs/articles/samples/IntroSummaryStyle.md index 0214bbd2be..ded29a6f8d 100644 --- a/docs/articles/samples/IntroSummaryStyle.md +++ b/docs/articles/samples/IntroSummaryStyle.md @@ -12,7 +12,7 @@ You can customize the summary report by specifying various properties of `Summar ### Source Code -[!code-csharp[SummaryStyle.cs](../../../samples/BenchmarkDotNet.Samples/IntroSummaryStyle.cs)] +[!code-csharp[IntroSummaryStyle.cs](../../../samples/BenchmarkDotNet.Samples/IntroSummaryStyle.cs)] ### Properties From cbd98ea13b2016dc63ea225cc3988868be33cb3c Mon Sep 17 00:00:00 2001 From: Matt Chaulklin Date: Tue, 23 Jan 2024 12:57:00 -0500 Subject: [PATCH 3/3] correct spelling --- docs/articles/samples/IntroSummaryStyle.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/articles/samples/IntroSummaryStyle.md b/docs/articles/samples/IntroSummaryStyle.md index ded29a6f8d..470bb901a1 100644 --- a/docs/articles/samples/IntroSummaryStyle.md +++ b/docs/articles/samples/IntroSummaryStyle.md @@ -26,7 +26,7 @@ You can customize the summary report by specifying various properties of `Summar ### Example Output -Using SummarySyle options: +Using SummaryStyle options: ```markdown | Method | N | Mean [ns] | Error [ns] | StdDev [ns] | @@ -46,6 +46,6 @@ Default: ### Links -* @docs.summarystyle +* @docs.SummaryStyle * The permanent link to this sample: @BenchmarkDotNet.Samples.IntroSummaryStyle