Skip to content
Navigation Menu
{{ message }}
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathProgram.cs
More file actions
248 lines (225 loc) · 11.4 KB
/
Copy pathProgram.cs
File metadata and controls
248 lines (225 loc) · 11.4 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
// <copyright file="Program.cs" company="MPCoreDeveloper">
// Copyright (c) 2025-2026 MPCoreDeveloper and GitHub Copilot. All rights reserved.
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Exporters.Csv;
using BenchmarkDotNet.Exporters.Json;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Order;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;
using SharpCoreDB.Benchmarks;
static IConfig CreateQuickConfig()
{
var job = Job.InProcess
.WithId("QuickHost")
.WithWarmupCount(1) // ? At least 1 warmup for JIT
.WithIterationCount(3) // ? 3 iterations for statistical stability
.WithLaunchCount(1)
// Use in-process emit (default) to restore original working mode
.WithToolchain(BenchmarkDotNet.Toolchains.InProcess.Emit.InProcessEmitToolchain.Instance);
var resultsPath = Path.Combine("BenchmarkDotNet.Artifacts", "results");
Directory.CreateDirectory(resultsPath);
// ? NEW: Create a timestamped log file for THIS run
var timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
var logFilePath = Path.Combine(resultsPath, $"benchmark_log_{timestamp}.txt");
var config = ManualConfig.CreateEmpty();
config.UnionRule = ConfigUnionRule.AlwaysUseLocal;
return config
.AddJob(job)
.AddLogger(ConsoleLogger.Default)
.AddLogger(new StreamLogger(new StreamWriter(logFilePath) { AutoFlush = true })) // ? ALWAYS log to file!
.AddColumnProvider(DefaultColumnProviders.Instance)
.WithOrderer(new DefaultOrderer(SummaryOrderPolicy.FastestToSlowest))
.AddDiagnoser(MemoryDiagnoser.Default)
.AddExporter(MarkdownExporter.GitHub)
.AddExporter(CsvExporter.Default)
.AddExporter(HtmlExporter.Default)
.AddExporter(JsonExporter.Full)
.AddExporter(RPlotExporter.Default) // ? Add R plots
.WithArtifactsPath(resultsPath)
.WithOptions(ConfigOptions.DisableOptimizationsValidator | ConfigOptions.JoinSummary);
}
var config = CreateQuickConfig();
Console.WriteLine("==============================================");
Console.WriteLine(" SharpCoreDB Benchmarks Menu (Quick Mode)");
Console.WriteLine("==============================================");
Console.WriteLine("Select a benchmark to run:");
Console.WriteLine(" 1) Page-based storage before/after (PageBasedStorageBenchmark)");
Console.WriteLine(" 2) Cross-engine comparison (StorageEngineComparisonBenchmark)");
Console.WriteLine(" 3) UPDATE performance - Priority 1 validation (UpdatePerformanceTest)");
Console.WriteLine(" 4) SELECT optimization - Phase-by-phase speedup (SelectOptimizationTest)");
Console.WriteLine(" 5) StructRow API - Zero-copy performance (StructRowBenchmark)");
Console.WriteLine(" 6) Phase 2A Optimizations - WHERE/SELECT*/Type conversion/Batch (Phase2AOptimizationBenchmark)");
Console.WriteLine(" 7) Hash index backend comparison (HashIndexBackendBenchmark)");
Console.WriteLine(" 0) Exit");
Console.WriteLine();
Console.Write("Enter choice: ");
var input = Console.ReadLine()?.Trim();
// Fallback for non-interactive runs: default to option 2 (cross-engine comparison)
if (string.IsNullOrWhiteSpace(input))
{
// Try to infer a choice from command-line args (e.g., passing "2")
try
{
var cmdArgs = Environment.GetCommandLineArgs();
var choiceArg = cmdArgs.FirstOrDefault(a => a == "1" || a == "2" || a == "3" || a == "4" || a == "5" || a == "6" || a == "7" || a == "0" || a?.Equals("q", StringComparison.OrdinalIgnoreCase) == true);
input = string.IsNullOrWhiteSpace(choiceArg) ? "2" : choiceArg; // Default to 2 when no explicit choice
}
catch
{
input = "2"; // Safe default
}
}
Summary? summary = null;
// ? GUARANTEED: Log file that ALWAYS gets written
var timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
var logPath = Path.Combine("BenchmarkDotNet.Artifacts", "results", $"run_{timestamp}.log");
Directory.CreateDirectory(Path.GetDirectoryName(logPath)!);
var logWriter = new StreamWriter(logPath, append: true) { AutoFlush = true };
try
{
logWriter.WriteLine($"=== Benchmark Run Started: {DateTime.Now:yyyy-MM-dd HH:mm:ss} ===");
logWriter.WriteLine($"Selected option: {input}");
logWriter.WriteLine();
switch (input)
{
case "1":
Console.WriteLine("Running PageBasedStorageBenchmark (Quick)…");
logWriter.WriteLine("Running PageBasedStorageBenchmark...");
summary = BenchmarkRunner.Run<PageBasedStorageBenchmark>(config);
break;
case "2":
Console.WriteLine("Running StorageEngineComparisonBenchmark (Quick)…");
logWriter.WriteLine("Running StorageEngineComparisonBenchmark...");
summary = BenchmarkRunner.Run<StorageEngineComparisonBenchmark>(config);
break;
case "3":
Console.WriteLine("Running UpdatePerformanceTest (UPDATE Performance Validation)...");
logWriter.WriteLine("Running UpdatePerformanceTest...");
UpdatePerformanceTest.Main();
Console.WriteLine("\nUpdatePerformanceTest completed.");
logWriter.WriteLine("UpdatePerformanceTest completed.");
break;
case "4":
Console.WriteLine("Running SelectOptimizationTest (SELECT Phase-by-Phase Speedup)...");
logWriter.WriteLine("Running SelectOptimizationTest...");
SelectOptimizationTest.Main().GetAwaiter().GetResult();
Console.WriteLine("\nSelectOptimizationTest completed.");
logWriter.WriteLine("SelectOptimizationTest completed.");
break;
case "5":
Console.WriteLine("Running StructRowBenchmark (Zero-Copy API Performance)...");
logWriter.WriteLine("Running StructRowBenchmark...");
StructRowBenchmark.RunBenchmarks();
CrossEngineBenchmark.RunCrossEngineBenchmarks();
Console.WriteLine("\nStructRowBenchmark completed.");
logWriter.WriteLine("StructRowBenchmark completed.");
break;
case "6":
Console.WriteLine("Running Phase2AOptimizationBenchmark (Phase 2A Optimizations)...");
logWriter.WriteLine("Running Phase2AOptimizationBenchmark...");
summary = BenchmarkRunner.Run<Phase2AOptimizationBenchmark>(config);
Console.WriteLine("\nPhase2AOptimizationBenchmark completed.");
logWriter.WriteLine("Phase2AOptimizationBenchmark completed.");
break;
case "7":
Console.WriteLine("Running HashIndexBackendBenchmark (classic vs unsafe backend)...");
logWriter.WriteLine("Running HashIndexBackendBenchmark...");
summary = BenchmarkRunner.Run<HashIndexBackendBenchmark>(config);
Console.WriteLine("\nHashIndexBackendBenchmark completed.");
logWriter.WriteLine("HashIndexBackendBenchmark completed.");
break;
case "0":
case "q":
case "Q":
Console.WriteLine("Exiting.");
logWriter.WriteLine("User exited.");
break;
default:
// If invalid input provided, default to option 2 for CI stability
Console.WriteLine("Invalid choice. Defaulting to option 2 (Cross-engine comparison).\n");
logWriter.WriteLine($"Invalid choice: {input}. Defaulting to option 2.");
summary = BenchmarkRunner.Run<StorageEngineComparisonBenchmark>(config);
break;
}
logWriter.WriteLine();
logWriter.WriteLine($"=== Benchmark Run Completed: {DateTime.Now:yyyy-MM-dd HH:mm:ss} ===");
logWriter.WriteLine($"Summary is null: {summary == null}");
if (summary != null)
{
logWriter.WriteLine($"Total reports: {summary.Reports.Length}");
logWriter.WriteLine($"Successful reports: {summary.Reports.Count(r => r.Success)}");
}
}
finally
{
logWriter?.Dispose();
Console.WriteLine($"\n? Run log saved to: {logPath}");
}
// ? NEW: Save a simple summary file
if (summary != null)
{
try
{
var summaryPath = Path.Combine("BenchmarkDotNet.Artifacts", "results", $"SUMMARY_{DateTime.Now:yyyyMMdd_HHmmss}.txt");
var summaryText = new System.Text.StringBuilder();
summaryText.AppendLine("==============================================");
summaryText.AppendLine($" Benchmark Summary - {DateTime.Now:yyyy-MM-dd HH:mm:ss}");
summaryText.AppendLine("==============================================");
summaryText.AppendLine();
summaryText.AppendLine($"Total benchmarks: {summary.Reports.Length}");
summaryText.AppendLine($"Successful: {summary.Reports.Count(r => r.Success)}");
summaryText.AppendLine($"Failed: {summary.Reports.Count(r => !r.Success)}");
summaryText.AppendLine();
if (summary.Reports.Any(r => r.Success))
{
summaryText.AppendLine("RESULTS:");
summaryText.AppendLine();
// ? ENHANCED: Add full table output
summaryText.AppendLine("| Method | Categories | Mean | Error | StdDev | Ratio | RatioSD | Allocated | Alloc Ratio |");
summaryText.AppendLine("|--------|-----------|------|-------|--------|-------|---------|-----------|-------------|");
foreach (var report in summary.Reports.Where(r => r.Success).OrderBy(r => r.ResultStatistics?.Mean ?? double.MaxValue))
{
var method = report.BenchmarkCase.Descriptor.WorkloadMethod.Name;
var category = report.BenchmarkCase.Descriptor.Categories.FirstOrDefault() ?? "N/A";
var stats = report.ResultStatistics;
var mean = stats?.Mean ?? 0;
var error = stats?.StandardError ?? 0;
var stdDev = stats?.StandardDeviation ?? 0;
var unit = "ns";
if (mean > 1_000_000_000) { mean /= 1_000_000_000; error /= 1_000_000_000; stdDev /= 1_000_000_000; unit = "s"; }
else if (mean > 1_000_000) { mean /= 1_000_000; error /= 1_000_000; stdDev /= 1_000_000; unit = "ms"; }
else if (mean > 1_000) { mean /= 1_000; error /= 1_000; stdDev /= 1_000; unit = "us"; }
summaryText.AppendLine($"| {method,-30} | {category,-10} | {mean,8:F2} {unit} | {error,8:F2} {unit} | {stdDev,8:F2} {unit} | - | - | - | - |");
}
}
if (summary.Reports.Any(r => !r.Success))
{
summaryText.AppendLine();
summaryText.AppendLine("FAILED BENCHMARKS:");
foreach (var report in summary.Reports.Where(r => !r.Success))
{
summaryText.AppendLine($" - {report.BenchmarkCase.Descriptor.WorkloadMethod.Name}");
}
}
File.WriteAllText(summaryPath, summaryText.ToString());
Console.WriteLine();
Console.WriteLine($"? Summary saved to: {summaryPath}");
Console.WriteLine($" File size: {new FileInfo(summaryPath).Length} bytes");
}
catch (Exception ex)
{
Console.WriteLine($"? ERROR saving summary: {ex.Message}");
Console.WriteLine($" Stack trace: {ex.StackTrace}");
}
}
else
{
Console.WriteLine("?? WARNING: Summary was NULL - no results to save!");
}
You can’t perform that action at this time.
