-
Notifications
You must be signed in to change notification settings - Fork 6
/
Program.cs
180 lines (152 loc) · 8.12 KB
/
Program.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
using BenchmarkDotNetVisualizer;
using BenchmarkDotNetVisualizer.Utilities;
#region Create reports from artifacts
//var directory = Path.Combine(DirectoryHelper.GetProjectBenchmarkArtifactsDirectory(), "results (final)");
//var initializeBenchmarkInfo = BenchmarkInfo.CreateFromDirectory(directory, searchPattern: "Benchmarks.InitializeBenchmark*-report-github.md").ToArray();
//await VisualizeInitializeBenchmarks(initializeBenchmarkInfo);
//var containsBenchmarkInfo = BenchmarkInfo.CreateFromDirectory(directory, searchPattern: "Benchmarks.ContainsBenchmark*-report-github.md").ToArray();
//await VisualizeContainsBenchmarks(containsBenchmarkInfo);
//var tryGetValueBenchmarkInfo = BenchmarkInfo.CreateFromDirectory(directory, searchPattern: "Benchmarks.TryGetValueBenchmark*-report-github.md").ToArray();
//await VisualizeTryGetValueBenchmarks(tryGetValueBenchmarkInfo);
//return;
#endregion
var benchmarkInfo = BenchmarkAutoRunner.SwitcherRun(typeof(Program).Assembly).GetBenchmarkInfo().ToArray();
DirectoryHelper.MoveBenchmarkArtifactsToProjectDirectory();
#region Create reports from summaries
var initializeBenchmarkInfo2 = Array.FindAll(benchmarkInfo, p => p.BenchmarkType.GetGenericTypeDefinition() == typeof(Benchmarks.InitializeBenchmark<>));
await VisualizeInitializeBenchmarks(initializeBenchmarkInfo2);
var containsBenchmarkInfo2 = Array.FindAll(benchmarkInfo, p => p.BenchmarkType.GetGenericTypeDefinition() == typeof(Benchmarks.ContainsBenchmark<>));
await VisualizeContainsBenchmarks(containsBenchmarkInfo2);
var tryGetValueBenchmarkInfo2 = Array.FindAll(benchmarkInfo, p => p.BenchmarkType.GetGenericTypeDefinition() == typeof(Benchmarks.TryGetValueBenchmark<>));
await VisualizeTryGetValueBenchmarks(tryGetValueBenchmarkInfo2);
#endregion
Console.ReadLine();
#region Visualizer Customization
static async Task VisualizeInitializeBenchmarks(BenchmarkInfo[] benchmarkInfo)
{
if (benchmarkInfo is not { Length: > 0 })
return;
var options = new JoinReportHtmlOptions()
{
Title = null!, //Set per case
MainColumn = "Method",
GroupByColumns = ["Length", "Sorted"],
PivotColumn = "DataType",
StatisticColumns = null!, //Set per case
ColumnsOrder = ["Int32", "String", "StructInts", "ClassInts", "RecordStructInts", "RecordClassInts", "StructStrings", "ClassStrings", "RecordStructStrings", "RecordClassStrings"],
SpectrumStatisticColumn = true,
HighlightGroups = true,
DividerMode = RenderTableDividerMode.SeparateTables,
HtmlWrapMode = HtmlDocumentWrapMode.RichDataTables,
Theme = Theme.Light
};
options.Title = "Benchmark of Collection Initializing in terms of Execution Time (Mean)";
options.StatisticColumns = ["Mean"];
await benchmarkInfo.JoinReportsAndSaveAsHtmlAndImageAsync(
htmlPath: DirectoryHelper.GetPathRelativeToProjectDirectory("docs\\Benchmark-Initialize-Mean.html"),
imagePath: DirectoryHelper.GetPathRelativeToProjectDirectory("docs\\Benchmark-Initialize-Mean.png"),
options: options);
options.Title = "Benchmark of Collection Initializing in terms of Allocation Size";
options.StatisticColumns = ["Allocated"];
await benchmarkInfo.JoinReportsAndSaveAsHtmlAndImageAsync(
htmlPath: DirectoryHelper.GetPathRelativeToProjectDirectory("docs\\Benchmark-Initialize-Allocated.html"),
imagePath: DirectoryHelper.GetPathRelativeToProjectDirectory("docs\\Benchmark-Initialize-Allocated.png"),
options: options);
}
static async Task VisualizeContainsBenchmarks(BenchmarkInfo[] benchmarkInfo)
{
if (benchmarkInfo is not { Length: > 0 })
return;
ChangeColorAndNameOfBigOColumn(benchmarkInfo);
var options = new JoinReportHtmlOptions()
{
Title = null!, //Set per case
MainColumn = "Method",
GroupByColumns = ["Existed"],
PivotColumn = "DataType",
StatisticColumns = null!, //Set per case
OtherColumnsToSelect = ["Big O", "Length"],
ColumnsOrder = ["Int32", "String", "StructInts", "ClassInts", "RecordStructInts", "RecordClassInts", "StructStrings", "ClassStrings", "RecordStructStrings", "RecordClassStrings"],
SpectrumStatisticColumn = true,
HighlightGroups = true,
DividerMode = RenderTableDividerMode.SeparateTables,
HtmlWrapMode = HtmlDocumentWrapMode.RichDataTables,
Theme = Theme.Light
};
options.Title = "Benchmark of Collection Searching (Contains method) in terms of Execution Time (Mean)";
options.StatisticColumns = ["Mean"];
await benchmarkInfo.JoinReportsAndSaveAsHtmlAndImageAsync(
htmlPath: DirectoryHelper.GetPathRelativeToProjectDirectory("docs\\Benchmark-SearchContains-Mean.html"),
imagePath: DirectoryHelper.GetPathRelativeToProjectDirectory("docs\\Benchmark-SearchContains-Mean.png"),
options: options);
options.Title = "Benchmark of Collection Searching (Contains method) in terms of Allocation Size";
options.StatisticColumns = ["Allocated"];
await benchmarkInfo.JoinReportsAndSaveAsHtmlAndImageAsync(
htmlPath: DirectoryHelper.GetPathRelativeToProjectDirectory("docs\\Benchmark-SearchContains-Allocated.html"),
imagePath: DirectoryHelper.GetPathRelativeToProjectDirectory("docs\\Benchmark-SearchContains-Allocated.png"),
options: options);
}
static async Task VisualizeTryGetValueBenchmarks(BenchmarkInfo[] benchmarkInfo)
{
if (benchmarkInfo is not { Length: > 0 })
return;
ChangeColorAndNameOfBigOColumn(benchmarkInfo);
var options = new JoinReportHtmlOptions()
{
Title = null!, //Set per case
MainColumn = "Method",
GroupByColumns = ["Existed"],
PivotColumn = "DataType",
StatisticColumns = null!, //Set per case
OtherColumnsToSelect = ["Big O", "Length"],
ColumnsOrder = ["Int32", "String", "StructInts", "ClassInts", "RecordStructInts", "RecordClassInts", "StructStrings", "ClassStrings", "RecordStructStrings", "RecordClassStrings"],
SpectrumStatisticColumn = true,
HighlightGroups = true,
DividerMode = RenderTableDividerMode.SeparateTables,
HtmlWrapMode = HtmlDocumentWrapMode.RichDataTables,
Theme = Theme.Light
};
options.Title = "Benchmark of Collection Searching (TryGetValue method) in terms of Execution Time (Mean)";
options.StatisticColumns = ["Mean"];
await benchmarkInfo.JoinReportsAndSaveAsHtmlAndImageAsync(
htmlPath: DirectoryHelper.GetPathRelativeToProjectDirectory("docs\\Benchmark-SearchTryGetValue-Mean.html"),
imagePath: DirectoryHelper.GetPathRelativeToProjectDirectory("docs\\Benchmark-SearchTryGetValue-Mean.png"),
options: options);
options.Title = "Benchmark of Collection Searching (TryGetValue method) in terms of Allocation Size";
options.StatisticColumns = ["Allocated"];
await benchmarkInfo.JoinReportsAndSaveAsHtmlAndImageAsync(
htmlPath: DirectoryHelper.GetPathRelativeToProjectDirectory("docs\\Benchmark-SearchTryGetValue-Allocated.html"),
imagePath: DirectoryHelper.GetPathRelativeToProjectDirectory("docs\\Benchmark-SearchTryGetValue-Allocated.png"),
options: options);
}
static void ChangeColorAndNameOfBigOColumn(BenchmarkInfo[] benchmarkInfo)
{
const string srcPropertyName = "Categories";
const string destPropertyName = "Big O";
foreach (var item in benchmarkInfo)
{
item.Table = item.Table.Select(expando =>
{
if (expando is not null)
{
expando.ChangePropertyName(srcPropertyName, destPropertyName);
expando.TransferColumnOrder(srcPropertyName, destPropertyName);
var value = expando.GetProperty(destPropertyName).ToString().RemoveMarkdownBold();
var color = GetColor(value);
expando.SetMetaProperty($"{destPropertyName}.background-color", color);
}
return expando;
});
}
static string GetColor(string value)
{
return value switch
{
"O(1)" => "#99FF99",
"O(log(N))" => "#FFFF99",
"O(N)" => "#FF9999",
_ => throw new ArgumentOutOfRangeException()
};
}
}
#endregion