Repository navigation
Expand file tree
/
Copy pathbenchmark_tool.cpp
More file actions
279 lines (246 loc) · 11.2 KB
/
Copy pathbenchmark_tool.cpp
File metadata and controls
279 lines (246 loc) · 11.2 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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#include <algorithm>
#include <chrono>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#include "include/bolt/core/benchmark_suite.hpp"
#include "include/bolt/core/logging.hpp"
using namespace bolt; // NOLINT(build/namespaces)
void printUsage(const char* programName) {
std::cout << "Usage: " << programName << " [options]\n\n";
std::cout << "Options:\n";
std::cout << " --help, -h Show this help message\n";
std::cout << " --list, -l List available benchmarks\n";
std::cout << " --categories, -c List available categories\n";
std::cout << " --run-all, -a Run all benchmarks\n";
std::cout << " --category <name> Run benchmarks in specific category\n";
std::cout << " --benchmark <name> Run specific benchmark\n";
std::cout << " --iterations <n> Set number of iterations (default: 10)\n";
std::cout << " --warmup <n> Set number of warmup runs (default: 3)\n";
std::cout << " --timeout <ms> Set timeout in milliseconds (default: 30000)\n";
std::cout << " --output-json <file> Generate JSON report\n";
std::cout << " --output-csv <file> Generate CSV report\n";
std::cout << " --output-html <file> Generate HTML report\n";
std::cout << " --baseline <file> Load baseline results for comparison\n";
std::cout << " --save-baseline <file> Save results as baseline\n";
std::cout << " --verbose, -v Enable verbose output\n";
std::cout << "\nExamples:\n";
std::cout << " " << programName << " --run-all --output-html benchmark_report.html\n";
std::cout << " " << programName << " --category CORE --verbose\n";
std::cout << " " << programName << " --benchmark memory_allocation_basic --iterations 100\n";
std::cout << "\n";
}
void printBenchmarkSummary(const std::vector<BenchmarkResult>& results) {
std::cout << "\n=== Benchmark Summary ===\n";
std::cout << std::left << std::setw(30) << "Benchmark" << std::setw(12) << "Category" << std::setw(15)
<< "Avg Time (ms)" << std::setw(15) << "Min Time (ms)" << std::setw(15) << "Max Time (ms)"
<< std::setw(12) << "Success Rate"
<< "Status\n";
std::cout << std::string(110, '-') << "\n";
for (const auto& result : results) {
std::string status = result.isValid() ? "SUCCESS" : "FAILED";
std::cout << std::left << std::setw(30) << result.name.substr(0, 29) << std::setw(12) << result.category
<< std::setw(15) << std::fixed << std::setprecision(3) << result.averageDurationMs << std::setw(15)
<< std::fixed << std::setprecision(3) << result.minDurationMs << std::setw(15) << std::fixed
<< std::setprecision(3) << result.maxDurationMs << std::setw(12) << std::fixed << std::setprecision(1)
<< (result.getSuccessRate() * 100) << "%" << status << "\n";
if (!result.errorMessage.empty()) {
std::cout << " Error: " << result.errorMessage << "\n";
}
}
// Calculate summary statistics
int totalSuccessful = 0, totalFailed = 0;
double totalTime = 0.0;
for (const auto& result : results) {
if (result.isValid()) {
totalSuccessful++;
totalTime += result.averageDurationMs;
} else {
totalFailed++;
}
}
std::cout << "\n";
std::cout << "Total Benchmarks: " << results.size() << "\n";
std::cout << "Successful: " << totalSuccessful << "\n";
std::cout << "Failed: " << totalFailed << "\n";
if (totalSuccessful > 0) {
std::cout << "Average Time: " << std::fixed << std::setprecision(3) << (totalTime / totalSuccessful) << " ms\n";
}
}
void printComparisonSummary(const std::vector<BenchmarkComparison>& comparisons) {
std::cout << "\n=== Baseline Comparison ===\n";
std::cout << std::left << std::setw(30) << "Benchmark" << std::setw(15) << "Current (ms)" << std::setw(15)
<< "Baseline (ms)" << std::setw(12) << "Change (%)"
<< "Status\n";
std::cout << std::string(80, '-') << "\n";
int improvements = 0, regressions = 0, stable = 0;
for (const auto& comp : comparisons) {
std::string statusStr;
switch (comp.performanceStatus) {
case BenchmarkComparison::Status::IMPROVED:
statusStr = "IMPROVED";
improvements++;
break;
case BenchmarkComparison::Status::DEGRADED:
statusStr = "DEGRADED";
regressions++;
break;
case BenchmarkComparison::Status::STABLE:
statusStr = "STABLE";
stable++;
break;
default:
statusStr = "INCONCLUSIVE";
break;
}
std::cout << std::left << std::setw(30) << comp.benchmarkName.substr(0, 29) << std::setw(15) << std::fixed
<< std::setprecision(3) << comp.current.averageDurationMs << std::setw(15) << std::fixed
<< std::setprecision(3) << comp.baseline.averageDurationMs << std::setw(12) << std::fixed
<< std::setprecision(1) << comp.durationChangePercent << statusStr << "\n";
}
std::cout << "\nComparison Summary:\n";
std::cout << "Improvements: " << improvements << "\n";
std::cout << "Regressions: " << regressions << "\n";
std::cout << "Stable: " << stable << "\n";
if (regressions > 0) {
std::cout << "\n⚠️ Performance regressions detected!\n";
} else if (improvements > 0) {
std::cout << "\n✅ Performance improvements found!\n";
}
}
int main(int argc, char* argv[]) {
// Initialize logging
LogManager::configureConsoleLogging(LogLevel::INFO, false);
auto& suite = BenchmarkSuite::getInstance();
// Command line argument parsing
std::string command;
std::string specificBenchmark;
std::string specificCategory;
std::string jsonOutput;
std::string csvOutput;
std::string htmlOutput;
std::string baselineFile;
std::string saveBaselineFile;
int iterations = 10;
int warmup = 3;
int timeout = 30000;
bool verbose = false;
for (int i = 1; i < argc; ++i) {
std::string arg = argv[i];
if (arg == "--help" || arg == "-h") {
printUsage(argv[0]);
return 0;
} else if (arg == "--list" || arg == "-l") {
command = "list";
} else if (arg == "--categories" || arg == "-c") {
command = "categories";
} else if (arg == "--run-all" || arg == "-a") {
command = "run-all";
} else if (arg == "--verbose" || arg == "-v") {
verbose = true;
} else if (arg == "--category" && i + 1 < argc) {
command = "category";
specificCategory = argv[++i];
} else if (arg == "--benchmark" && i + 1 < argc) {
command = "benchmark";
specificBenchmark = argv[++i];
} else if (arg == "--iterations" && i + 1 < argc) {
iterations = std::stoi(argv[++i]);
} else if (arg == "--warmup" && i + 1 < argc) {
warmup = std::stoi(argv[++i]);
} else if (arg == "--timeout" && i + 1 < argc) {
timeout = std::stoi(argv[++i]);
} else if (arg == "--output-json" && i + 1 < argc) {
jsonOutput = argv[++i];
} else if (arg == "--output-csv" && i + 1 < argc) {
csvOutput = argv[++i];
} else if (arg == "--output-html" && i + 1 < argc) {
htmlOutput = argv[++i];
} else if (arg == "--baseline" && i + 1 < argc) {
baselineFile = argv[++i];
} else if (arg == "--save-baseline" && i + 1 < argc) {
saveBaselineFile = argv[++i];
} else {
std::cerr << "Unknown argument: " << arg << std::endl;
printUsage(argv[0]);
return 1;
}
}
if (command.empty()) {
command = "run-all"; // Default action
}
// Configure benchmark suite
suite.setDefaultIterations(iterations);
suite.setDefaultWarmupRuns(warmup);
suite.setDefaultTimeout(std::chrono::milliseconds(timeout));
suite.enableVerboseOutput(verbose);
// Load core benchmarks by including the source
// This ensures the benchmarks are registered
extern void register_core_benchmarks(); // Forward declaration
std::cout << "Bolt Performance Benchmark Suite\n";
std::cout << "================================\n\n";
try {
if (command == "list") {
auto benchmarks = suite.getAvailableBenchmarks();
std::cout << "Available Benchmarks:\n";
for (const auto& name : benchmarks) {
std::cout << " " << name << "\n";
}
std::cout << "\nTotal: " << benchmarks.size() << " benchmarks\n";
} else if (command == "categories") {
auto categories = suite.getAvailableCategories();
std::cout << "Available Categories:\n";
for (const auto& category : categories) {
std::cout << " " << category << "\n";
}
std::cout << "\nTotal: " << categories.size() << " categories\n";
} else if (command == "run-all") {
std::cout << "Running all benchmarks...\n";
auto results = suite.runAllBenchmarks();
printBenchmarkSummary(results);
// Handle baseline comparison
if (!baselineFile.empty()) {
auto baseline = suite.loadBaselineResults(baselineFile);
if (!baseline.empty()) {
auto comparisons = suite.compareWithBaseline(results, baseline);
printComparisonSummary(comparisons);
}
}
// Generate reports
if (!jsonOutput.empty()) {
suite.generateJsonReport(results, jsonOutput);
}
if (!csvOutput.empty()) {
suite.generateCsvReport(results, csvOutput);
}
if (!htmlOutput.empty()) {
suite.generateHtmlReport(results, htmlOutput);
}
if (!saveBaselineFile.empty()) {
suite.saveBaselineResults(results, saveBaselineFile);
}
} else if (command == "category") {
std::cout << "Running benchmarks in category: " << specificCategory << "\n";
auto results = suite.runBenchmarksByCategory(specificCategory);
if (results.empty()) {
std::cout << "No benchmarks found in category: " << specificCategory << "\n";
return 1;
}
printBenchmarkSummary(results);
} else if (command == "benchmark") {
std::cout << "Running benchmark: " << specificBenchmark << "\n";
auto result = suite.runBenchmark(specificBenchmark);
std::vector<BenchmarkResult> results = {result};
printBenchmarkSummary(results);
if (!result.isValid()) {
return 1;
}
}
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}
std::cout << "\nBenchmark execution completed.\n";
return 0;
}