1use serde::{Deserialize, Serialize};
8use std::collections::{HashMap, VecDeque};
9use std::time::{Duration, SystemTime};
10
11use super::analyzers::*;
13use super::metrics::*;
14
15pub struct BenchmarkEngine {
16 pub benchmark_suites: HashMap<String, BenchmarkSuite>,
18 pub benchmark_results: HashMap<String, BenchmarkResult>,
20 pub comparison_results: ComparisonResults,
22 pub config: BenchmarkConfig,
24}
25
26#[derive(Debug, Clone)]
28pub struct BenchmarkSuite {
29 pub name: String,
31 pub tests: Vec<BenchmarkTest>,
33 pub config: BenchmarkSuiteConfig,
35 pub metadata: HashMap<String, String>,
37}
38
39#[derive(Debug, Clone)]
41pub struct BenchmarkTest {
42 pub name: String,
44 pub test_type: BenchmarkTestType,
46 pub parameters: HashMap<String, f64>,
48 pub expected_range: (f64, f64),
50}
51
52#[derive(Debug, Clone)]
54pub enum BenchmarkTestType {
55 Performance,
57 Stress,
59 Load,
61 Endurance,
63 Accuracy,
65}
66
67#[derive(Debug, Clone)]
69pub struct BenchmarkSuiteConfig {
70 pub iterations: usize,
72 pub warmup_iterations: usize,
74 pub test_timeout: Duration,
76 pub confidence_level: f64,
78}
79
80#[derive(Debug, Clone, Serialize, Deserialize)]
82pub struct BenchmarkResult {
83 pub timestamp: SystemTime,
85 pub suite_name: String,
87 pub test_results: HashMap<String, TestResult>,
89 pub overall_score: f64,
91 pub execution_duration: Duration,
93}
94
95#[derive(Debug, Clone, Serialize, Deserialize)]
97pub struct TestResult {
98 pub test_name: String,
100 pub score: f64,
102 pub execution_time: Duration,
104 pub passed: bool,
106 pub error_message: Option<String>,
108 pub metadata: HashMap<String, String>,
110}
111
112#[derive(Debug, Clone, Serialize, Deserialize)]
114pub struct ComparisonResults {
115 pub baseline: String,
117 pub comparisons: HashMap<String, ComparisonSummary>,
119 pub significance_tests: HashMap<String, f64>,
121 pub regression_analysis: RegressionAnalysisResults,
123}
124
125#[derive(Debug, Clone, Serialize, Deserialize)]
127pub struct ComparisonSummary {
128 pub improvement: f64,
130 pub significance: f64,
132 pub confidence_interval: (f64, f64),
134 pub effect_size: f64,
136}
137
138#[derive(Debug, Clone, Serialize, Deserialize)]
140pub struct RegressionAnalysisResults {
141 pub regressions: Vec<PerformanceRegression>,
143 pub severity_summary: HashMap<RegressionSeverity, usize>,
145 pub trend_analysis: TrendAnalysisResults,
147}
148
149#[derive(Debug, Clone, Serialize, Deserialize)]
151pub struct PerformanceRegression {
152 pub test_name: String,
154 pub magnitude: f64,
156 pub severity: RegressionSeverity,
158 pub confidence: f64,
160 pub probable_cause: Option<String>,
162}
163
164#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
166pub enum RegressionSeverity {
167 Minor,
169 Moderate,
171 Major,
173 Critical,
175}
176
177#[derive(Debug, Clone, Serialize, Deserialize)]
179pub struct TrendAnalysisResults {
180 pub trends: HashMap<String, TrendDirection>,
182 pub trend_strengths: HashMap<String, f64>,
184 pub forecast_confidence: HashMap<String, f64>,
186}
187
188#[derive(Debug, Clone, Serialize, Deserialize)]
190pub struct BenchmarkConfig {
191 pub default_iterations: usize,
193 pub default_timeout: Duration,
195 pub enable_statistical_analysis: bool,
197 pub comparison_baseline: Option<String>,
199 pub auto_regression_detection: bool,
201}
202
203#[derive(Debug, Clone)]
205pub struct RegressionDetector {
206 pub algorithms: HashMap<String, RegressionDetectionAlgorithm>,
208 pub detected_regressions: Vec<PerformanceRegression>,
210 pub config: RegressionDetectionConfig,
212 pub baseline_manager: BaselineManager,
214}
215
216#[derive(Debug, Clone)]
218pub struct RegressionDetectionAlgorithm {
219 pub algorithm_type: RegressionAlgorithmType,
221 pub parameters: HashMap<String, f64>,
223 pub sensitivity: f64,
225 pub false_positive_rate: f64,
227}
228
229#[derive(Debug, Clone)]
231pub enum RegressionAlgorithmType {
232 ChangePointDetection,
234 ControlChart,
236 TrendAnalysis,
238 MachineLearning,
240 Composite,
242}
243
244#[derive(Debug, Clone, Serialize, Deserialize)]
246pub struct RegressionDetectionConfig {
247 pub enable_continuous_monitoring: bool,
249 pub detection_window: Duration,
251 pub min_regression_magnitude: f64,
253 pub confidence_threshold: f64,
255}
256
257#[derive(Debug, Clone)]
259pub struct BaselineManager {
260 pub baselines: HashMap<String, PerformanceBaseline>,
262 pub update_policy: BaselineUpdatePolicy,
264 pub validation_results: BaselineValidationResults,
266}
267
268#[derive(Debug, Clone, Serialize, Deserialize)]
270pub struct PerformanceBaseline {
271 pub name: String,
273 pub values: HashMap<String, f64>,
275 pub timestamp: SystemTime,
277 pub confidence: f64,
279 pub validity_period: Duration,
281}
282
283#[derive(Debug, Clone, Serialize, Deserialize)]
285pub struct BaselineUpdatePolicy {
286 pub update_frequency: Duration,
288 pub min_data_points: usize,
290 pub update_threshold: f64,
292 pub auto_update: bool,
294}
295
296#[derive(Debug, Clone, Serialize, Deserialize)]
298pub struct BaselineValidationResults {
299 pub status: ValidationStatus,
301 pub score: f64,
303 pub timestamp: SystemTime,
305 pub errors: Vec<String>,
307}
308
309#[derive(Debug, Clone, Serialize, Deserialize)]
311pub enum ValidationStatus {
312 Valid,
314 Invalid,
316 NeedsValidation,
318 Validating,
320}