Skip to main content

ass_renderer/debug/benchmarking/
types.rs

1//! Data structures for benchmark configuration and results
2
3#[cfg(feature = "nostd")]
4use alloc::{string::String, vec::Vec};
5#[cfg(not(feature = "nostd"))]
6use std::{string::String, vec::Vec};
7
8/// Configuration for performance benchmarking
9#[derive(Debug, Clone)]
10pub struct BenchmarkConfig {
11    /// Number of iterations per test
12    pub iterations: usize,
13    /// Warmup iterations before measuring
14    pub warmup_iterations: usize,
15    /// Include memory usage measurement
16    pub measure_memory: bool,
17    /// Include frame rate measurement for animations
18    pub measure_frame_rate: bool,
19    /// Test different video resolutions
20    pub test_resolutions: Vec<(u32, u32)>,
21    /// Animation duration for frame rate tests (in centiseconds)
22    pub animation_duration_cs: u32,
23}
24
25impl Default for BenchmarkConfig {
26    fn default() -> Self {
27        Self {
28            iterations: 10,
29            warmup_iterations: 3,
30            measure_memory: true,
31            measure_frame_rate: true,
32            test_resolutions: vec![
33                (1280, 720),  // 720p
34                (1920, 1080), // 1080p
35                (3840, 2160), // 4K
36            ],
37            animation_duration_cs: 1000, // 10 seconds
38        }
39    }
40}
41
42/// Result of performance benchmark
43#[derive(Debug, Clone)]
44pub struct BenchmarkResult {
45    /// Test identifier
46    pub test_name: String,
47    /// Video resolution used
48    pub resolution: (u32, u32),
49    /// Our renderer performance
50    pub our_performance: PerformanceMetrics,
51    /// Performance ratio (our_time / reference_time), if a reference is available
52    pub performance_ratio: Option<f64>,
53    /// Memory usage comparison
54    pub memory_ratio: Option<f64>,
55    /// Compatibility score (0.0 = completely different, 1.0 = identical)
56    pub compatibility_score: f64,
57}
58
59/// Detailed performance metrics
60#[derive(Debug, Clone)]
61pub struct PerformanceMetrics {
62    /// Average rendering time per frame (milliseconds)
63    pub avg_render_time_ms: f64,
64    /// Minimum rendering time (milliseconds)
65    pub min_render_time_ms: f64,
66    /// Maximum rendering time (milliseconds)
67    pub max_render_time_ms: f64,
68    /// Standard deviation of render times
69    pub render_time_std_dev: f64,
70    /// Frames per second (for animation tests)
71    pub fps: Option<f64>,
72    /// Peak memory usage (bytes)
73    pub peak_memory_bytes: Option<usize>,
74    /// Average memory usage (bytes)
75    pub avg_memory_bytes: Option<usize>,
76    /// Cache hit rate (0.0 to 1.0)
77    pub cache_hit_rate: Option<f64>,
78}
79
80/// Performance report containing all benchmark results
81#[derive(Debug, Clone)]
82pub struct PerformanceReport {
83    /// Individual test results
84    pub results: Vec<BenchmarkResult>,
85    /// Summary statistics
86    pub summary: PerformanceSummary,
87}
88
89/// Summary of performance characteristics
90#[derive(Debug, Clone)]
91pub struct PerformanceSummary {
92    /// Total number of tests run
93    pub total_tests: usize,
94    /// Average performance ratio vs libass
95    pub avg_performance_ratio: f64,
96    /// Average compatibility score
97    pub avg_compatibility_score: f64,
98    /// Average frames per second
99    pub avg_fps: f64,
100    /// Name of fastest test
101    pub fastest_test: Option<String>,
102    /// Name of slowest test
103    pub slowest_test: Option<String>,
104}
105
106impl Default for PerformanceSummary {
107    fn default() -> Self {
108        Self {
109            total_tests: 0,
110            avg_performance_ratio: 1.0,
111            avg_compatibility_score: 1.0,
112            avg_fps: 0.0,
113            fastest_test: None,
114            slowest_test: None,
115        }
116    }
117}