torsh_sparse/performance_tools/export/
plot_data.rs1use std::time::SystemTime;
4
5#[derive(Debug, Clone)]
7pub struct PlotData {
8 pub operation_names: Vec<String>,
10 pub avg_times: Vec<f64>,
12 pub throughputs: Vec<f64>,
14 pub memory_usage: Vec<f64>,
16 pub timestamps: Vec<SystemTime>,
18}
19
20impl PlotData {
21 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 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 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}