torsh_sparse/performance_tools/export/
plot_data.rs

1//! Data structures for plotting and visualization
2
3use std::time::SystemTime;
4
5/// Data structure for plotting and visualization
6#[derive(Debug, Clone)]
7pub struct PlotData {
8    /// Operation names for x-axis labels
9    pub operation_names: Vec<String>,
10    /// Average execution times in milliseconds
11    pub avg_times: Vec<f64>,
12    /// Throughput values (operations per second)
13    pub throughputs: Vec<f64>,
14    /// Memory usage values in bytes
15    pub memory_usage: Vec<f64>,
16    /// Timestamps for time-series data
17    pub timestamps: Vec<SystemTime>,
18}
19
20impl PlotData {
21    /// Create empty plot data
22    pub fn new() -> Self {
23        Self {
24            operation_names: Vec::new(),
25            avg_times: Vec::new(),
26            throughputs: Vec::new(),
27            memory_usage: Vec::new(),
28            timestamps: Vec::new(),
29        }
30    }
31
32    /// Add a data point
33    pub fn add_point(&mut self, operation: String, time_ms: f64, throughput: f64, memory: f64) {
34        self.operation_names.push(operation);
35        self.avg_times.push(time_ms);
36        self.throughputs.push(throughput);
37        self.memory_usage.push(memory);
38        self.timestamps.push(SystemTime::now());
39    }
40
41    /// Get data for time-series plotting
42    pub fn time_series_data(&self) -> Vec<(SystemTime, f64, f64, f64)> {
43        self.timestamps
44            .iter()
45            .zip(&self.avg_times)
46            .zip(&self.throughputs)
47            .zip(&self.memory_usage)
48            .map(|(((time, avg_time), throughput), memory)| {
49                (*time, *avg_time, *throughput, *memory)
50            })
51            .collect()
52    }
53}
54
55impl Default for PlotData {
56    fn default() -> Self {
57        Self::new()
58    }
59}