-
Notifications
You must be signed in to change notification settings - Fork 279
/
Copy pathRecommendedConfig.cs
87 lines (80 loc) · 4.16 KB
/
RecommendedConfig.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Exporters.Json;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Reports;
using Perfolizer.Horology;
using Reporting;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
namespace BenchmarkDotNet.Extensions
{
public static class RecommendedConfig
{
private static IEnvironment Environment = new EnvironmentProvider();
public static IConfig Create(
DirectoryInfo artifactsPath,
ImmutableHashSet<string> mandatoryCategories,
int? partitionCount = null,
int? partitionIndex = null,
List<string> exclusionFilterValue = null,
List<string> categoryExclusionFilterValue = null,
Job job = null,
bool getDiffableDisasm = false)
{
if (job is null)
{
job = Job.Default
.WithWarmupCount(1) // 1 warmup is enough for our purpose
.WithIterationTime(TimeInterval.FromMilliseconds(250)) // the default is 0.5s per iteration, which is slighlty too much for us
.WithMinIterationCount(15)
.WithMaxIterationCount(20) // we don't want to run more that 20 iterations
.DontEnforcePowerPlan(); // make sure BDN does not try to enforce High Performance power plan on Windows
}
var config = ManualConfig.CreateEmpty()
.WithBuildTimeout(TimeSpan.FromMinutes(15)) // for slow machines
.AddLogger(ConsoleLogger.Default) // log output to console
.AddValidator(DefaultConfig.Instance.GetValidators().ToArray()) // copy default validators
.AddAnalyser(DefaultConfig.Instance.GetAnalysers().ToArray()) // copy default analysers
.AddExporter(MarkdownExporter.GitHub) // export to GitHub markdown
.AddColumnProvider(DefaultColumnProviders.Instance) // display default columns (method name, args etc)
.AddJob(job.AsDefault()) // tell BDN that this are our default settings
.WithArtifactsPath(artifactsPath.FullName)
.AddDiagnoser(MemoryDiagnoser.Default) // MemoryDiagnoser is enabled by default
.AddFilter(new PartitionFilter(partitionCount, partitionIndex))
.AddFilter(new ExclusionFilter(exclusionFilterValue))
.AddFilter(new CategoryExclusionFilter(categoryExclusionFilterValue))
.AddExporter(JsonExporter.Full) // make sure we export to Json
.AddColumn(StatisticColumn.Median, StatisticColumn.Min, StatisticColumn.Max)
.AddValidator(new MandatoryCategoryValidator(mandatoryCategories))
.AddValidator(TooManyTestCasesValidator.FailOnError)
.AddValidator(new UniqueArgumentsValidator()) // don't allow for duplicated arguments #404
.WithSummaryStyle(SummaryStyle.Default.WithMaxParameterColumnWidth(36)); // the default is 20 and trims too aggressively some benchmark results
if (Environment.IsLabEnvironment())
{
config = config.AddExporter(new PerfLabExporter());
}
if (getDiffableDisasm)
{
config = config.AddDiagnoser(CreateDisassembler());
}
return config;
}
private static DisassemblyDiagnoser CreateDisassembler()
=> new DisassemblyDiagnoser(new DisassemblyDiagnoserConfig(
maxDepth: 1, // TODO: is depth == 1 enough?
syntax: DisassemblySyntax.Masm, // TODO: enable diffable format
printSource: false, // we are not interested in getting C#
printInstructionAddresses: false, // would make the diffing hard, however could be useful to determine alignment
exportGithubMarkdown: false,
exportHtml: false,
exportCombinedDisassemblyReport: false,
exportDiff: false));
}
}