Skip to content

Commit

Permalink
JsonExporters refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyAkinshin committed Aug 20, 2016
1 parent 60bea38 commit a8b4e7b
Show file tree
Hide file tree
Showing 11 changed files with 284 additions and 66 deletions.
1 change: 1 addition & 0 deletions BenchmarkDotNet.sln.DotSettings
@@ -1,2 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_METHOD_ATTRIBUTE_ON_SAME_LINE/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=GC/@EntryIndexedValue">GC</s:String></wpf:ResourceDictionary>
202 changes: 194 additions & 8 deletions docs/guide/Configuration/Exporters.md
Expand Up @@ -4,16 +4,202 @@ An *exporter* allows you to export results of your benchmark in different format
`.\BenchmarkDotNet.Artifacts\results` directory. Default exporters are: csv, html and markdown.
Here is list of all available exporters:

## MiscExporters

There are some predefined exporters. Examples:

```cs
public IEnumerable<IExporter> GetExporters()
[AsciiDocExporter]
[CsvExporter]
[CsvMeasurementsExporter]
[HtmlExporter]
[MarkdownExporter]
[PlainExporter]
public class MyBenchmarkClass
```

## Json

BenchmarkDotNet has a set of json exporters. You can customize the following properties of these exporters:

* `fileNameSuffix`: a string which be placed in the end of target file name.
* `indentJson`=`false`/`true`: should we format json or not.
* `excludeMeasurements`=`false`/`true`: should we excldue detailed information about measurements or not (the final summary with statistics will be in the json file anyway),

Also there are a set of predefined json exporters. Example of usage:

```cs
[JsonExporterAttribute.Brief]
[JsonExporterAttribute.Full]
[JsonExporterAttribute.BriefCompressed]
[JsonExporterAttribute.FullCompressed]
[JsonExporter("-custom", indentJson: true, excludeMeasurements: true)]
public class IntroJsonExport
{
[Benchmark] public void Sleep10() => Thread.Sleep(10);
[Benchmark] public void Sleep20() => Thread.Sleep(20);
}
```

```cs
[Config(typeof(Config))]
public class IntroJsonExport2
{
private class Config : ManualConfig
{
public Config()
{
Add(JsonExporter.Brief);
Add(JsonExporter.Full);
Add(JsonExporter.BriefCompressed);
Add(JsonExporter.FullCompressed);
Add(JsonExporter.Custom("-custom", indentJson: true, excludeMeasurements: true));
}
}
}
```

Example of `IntroJsonExport-report-brief.json`:

```js
{
yield return MarkdownExporter.Default; // produces <BenchmarkName>-report-default.md
yield return MarkdownExporter.GitHub; // produces <BenchmarkName>-report-github.md
yield return MarkdownExporter.StackOverflow; // produces <BenchmarkName>-report-stackoverflow.md
yield return CsvExporter.Default; // produces <BenchmarkName>-report.csv
yield return CsvMeasurementsExporter.Default; // produces <BenchmarkName>-measurements.csv
yield return HtmlExporter.Default; // produces <BenchmarkName>-report.html
yield return PlainExporter.Default; // produces <BenchmarkName>-report.txt
"Title":"IntroJsonExport",
"HostEnvironmentInfo":{
"BenchmarkDotNetCaption":"BenchmarkDotNet-Dev.Core",
"BenchmarkDotNetVersion":"0.9.9.0",
"OsVersion":"Microsoft Windows NT 6.2.9200.0",
"ProcessorName":{
"IsValueCreated":true,
"Value":"Intel(R) Core(TM) i7-4702MQ CPU 2.20GHz"
},
"ProcessorCount":8,
"ClrVersion":"MS.NET 4.0.30319.42000",
"Architecture":"64-bit",
"HasAttachedDebugger":false,
"HasRyuJit":true,
"Configuration":"RELEASE",
"JitModules":"clrjit-v4.6.1586.0",
"DotNetCliVersion":"1.0.0-preview2-003121",
"ChronometerFrequency":2143474,
"HardwareTimerKind":"Tsc"
},
"Benchmarks":[
{
"ShortInfo":"IntroJsonExport_Sleep10",
"Type":"IntroJsonExport",
"Method":"Sleep10",
"MethodTitle":"Sleep10",
"Parameters":"",
"Properties":{
"Mode":"Throughput",
"Platform":"Host",
"Jit":"Host",
"Runtime":"Host",
"GcMode":"Host",
"WarmupCount":"Auto",
"TargetCount":"Auto",
"LaunchCount":"Auto",
"IterationTime":"Auto",
"Affinity":"Auto"
},
"Statistics":{
"N":20,
"Min":10287928.031875,
"LowerFence":10229901.2459375,
"Q1":10352130.9040625,
"Median":10393069.119375,
"Mean":10390116.844234375,
"Q3":10433617.3428125,
"UpperFence":10555847.000937503,
"Max":10473396.5165625,
"InterquartileRange":81486.438750000671,
"Outliers":[

],
"StandardError":12514.907849226243,
"Variance":3132458369.4924932,
"StandardDeviation":55968.36936603114,
"Skewness":-0.26688070240057665,
"Kurtosis":1.87502014055259,
"ConfidenceInterval":{
"Mean":10390116.844234375,
"Error":12514.907849226243,
"Level":6,
"Margin":24529.219384483436,
"Lower":10365587.624849891,
"Upper":10414646.063618859
},
"Percentiles":{
"P0":10287928.031875,
"P25":10354961.078906249,
"P50":10393069.119375,
"P67":10423662.05225,
"P80":10439024.7445,
"P85":10447944.260171875,
"P90":10461577.210718751,
"P95":10465571.164984375,
"P100":10473396.5165625
}
}
},{
"ShortInfo":"IntroJsonExport_Sleep20",
"Type":"IntroJsonExport",
"Method":"Sleep20",
"MethodTitle":"Sleep20",
"Parameters":"",
"Properties":{
"Mode":"Throughput",
"Platform":"Host",
"Jit":"Host",
"Runtime":"Host",
"GcMode":"Host",
"WarmupCount":"Auto",
"TargetCount":"Auto",
"LaunchCount":"Auto",
"IterationTime":"Auto",
"Affinity":"Auto"
},
"Statistics":{
"N":20,
"Min":20263046.11125,
"LowerFence":20185645.475625,
"Q1":20313096.286875002,
"Median":20336976.9121875,
"Mean":20351602.702031251,
"Q3":20398063.494375,
"UpperFence":20525514.305625,
"Max":20464617.251875,
"InterquartileRange":84967.207499999553,
"Outliers":[

],
"StandardError":11991.004261727438,
"Variance":2875683664.0953112,
"StandardDeviation":53625.401295424461,
"Skewness":0.15925629564588534,
"Kurtosis":2.0971344882863447,
"ConfidenceInterval":{
"Mean":20351602.702031251,
"Error":11991.004261727438,
"Level":6,
"Margin":23502.368352985777,
"Lower":20328100.333678264,
"Upper":20375105.070384238
},
"Percentiles":{
"P0":20263046.11125,
"P25":20313438.8965625,
"P50":20336976.9121875,
"P67":20388224.909718752,
"P80":20400439.8935,
"P85":20405415.752406247,
"P90":20409280.681625,
"P95":20413094.583750002,
"P100":20464617.251875
}
}
}
]
}
```

Expand Down
19 changes: 19 additions & 0 deletions samples/BenchmarkDotNet.Samples/Intro/IntroJsonExport.cs
@@ -0,0 +1,19 @@
using System.Threading;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes.Exporters;
using BenchmarkDotNet.Attributes.Jobs;

namespace BenchmarkDotNet.Samples.Intro
{
[DryJob]
[JsonExporterAttribute.Brief]
[JsonExporterAttribute.Full]
[JsonExporterAttribute.BriefCompressed]
[JsonExporterAttribute.FullCompressed]
[JsonExporter("-custom", indentJson: true, excludeMeasurements: true)]
public class IntroJsonExport
{
[Benchmark] public void Sleep10() => Thread.Sleep(10);
[Benchmark] public void Sleep20() => Thread.Sleep(20);
}
}

This file was deleted.

This file was deleted.

@@ -0,0 +1,47 @@
using System;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Exporters.Json;

namespace BenchmarkDotNet.Attributes.Exporters
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)]
public class JsonExporterAttribute : ExporterConfigBaseAttribute
{
protected JsonExporterAttribute(IExporter exporter) : base(exporter)
{
}

public JsonExporterAttribute(string fileNameSuffix = "", bool indentJson = false, bool excludeMeasurements = false)
: this(new JsonExporter(fileNameSuffix, indentJson, excludeMeasurements))
{
}

public class BriefAttribute : JsonExporterAttribute
{
public BriefAttribute() : base(JsonExporter.Brief)
{
}
}

public class Full : JsonExporterAttribute
{
public Full() : base(JsonExporter.Full)
{
}
}

public class BriefCompressed : JsonExporterAttribute
{
public BriefCompressed() : base(JsonExporter.BriefCompressed)
{
}
}

public class FullCompressed : JsonExporterAttribute
{
public FullCompressed() : base(JsonExporter.FullCompressed)
{
}
}
}
}
4 changes: 2 additions & 2 deletions src/BenchmarkDotNet.Core/Configs/ConfigParser.cs
Expand Up @@ -104,8 +104,8 @@ private class ConfigOption
{ "plain", new[] { PlainExporter.Default } },
{ "rplot", new[] { RPlotExporter.Default } },
{ "json", new[] { JsonExporter.Default } },
{ "briefjson", new[] { BriefJsonExporter.Default } },
{ "formattedjson", new[] { FormattedJsonExporter.Default } },
{ "briefjson", new[] { JsonExporter.Brief } },
{ "fulljson", new[] { JsonExporter.Full } },
{ "asciidoc", new[] { AsciiDocExporter.Default } },
};
private static Lazy<IExporter[]> allExporters = new Lazy<IExporter[]>(() => availableExporters.SelectMany(e => e.Value).ToArray());
Expand Down
10 changes: 6 additions & 4 deletions src/BenchmarkDotNet.Core/Exporters/DefaultExporters.cs
Expand Up @@ -11,9 +11,11 @@ public static class DefaultExporters
public static IExporter Markdown = MarkdownExporter.Default;
public static IExporter Plain = PlainExporter.Default;
public static IExporter RPlot = RPlotExporter.Default;
public static IExporter BriefJson = BriefJsonExporter.Default;
public static IExporter FormattedJson = FormattedJsonExporter.Default;
}


public static IExporter Json = JsonExporter.Default;
public static IExporter JsonBrief = JsonExporter.Brief;
public static IExporter JsonBriefCompressed = JsonExporter.BriefCompressed;
public static IExporter JsonFull = JsonExporter.Full;
public static IExporter JsonFullCompressed = JsonExporter.FullCompressed;
}
}
13 changes: 0 additions & 13 deletions src/BenchmarkDotNet.Core/Exporters/Json/BriefJsonExporter.cs

This file was deleted.

13 changes: 0 additions & 13 deletions src/BenchmarkDotNet.Core/Exporters/Json/FormattedJsonExporter.cs

This file was deleted.

19 changes: 15 additions & 4 deletions src/BenchmarkDotNet.Core/Exporters/Json/JsonExporter.cs
@@ -1,11 +1,22 @@
namespace BenchmarkDotNet.Exporters.Json
{
public class JsonExporter : JsonExporterBase, IExporter
public class JsonExporter : JsonExporterBase
{
public static readonly IExporter Default = new JsonExporter();
public static readonly IExporter Brief = new JsonExporter("-brief", indentJson: true, excludeMeasurements: true);
public static readonly IExporter Full = new JsonExporter("-full", indentJson: true, excludeMeasurements: false);
public static readonly IExporter BriefCompressed = new JsonExporter("-brief-compressed", indentJson: false, excludeMeasurements: false);
public static readonly IExporter FullCompressed = new JsonExporter("-full-compressed", indentJson: false, excludeMeasurements: false);

public JsonExporter() : base(indentJson: false, excludeMeasurements: false)
public static readonly IExporter Default = FullCompressed;

protected override string FileNameSuffix { get; } = string.Empty;

public JsonExporter(string fileNameSuffix = "", bool indentJson = false, bool excludeMeasurements = false) : base(indentJson, excludeMeasurements)
{
FileNameSuffix = fileNameSuffix;
}

public static IExporter Custom(string fileNameSuffix = "", bool indentJson = false, bool excludeMeasurements = false) =>
new JsonExporter(fileNameSuffix, indentJson, excludeMeasurements);
}
}
}

0 comments on commit a8b4e7b

Please sign in to comment.