use serde::{Deserialize, Serialize};
use std::time::Duration;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ExperimentResults {
pub performance_gain: f64,
pub memory_efficiency: f64,
pub accuracy_maintained: bool,
pub device_compatibility: Vec<String>,
pub total_execution_time: Duration,
pub conversion_cost_reduction: f64,
}
impl ExperimentResults {
pub fn new() -> Self {
crate::hybrid_f32_experimental!();
Self {
performance_gain: 0.0,
memory_efficiency: 0.0,
accuracy_maintained: true,
device_compatibility: vec!["CPU".to_string()],
total_execution_time: Duration::from_secs(0),
conversion_cost_reduction: 0.0,
}
}
pub fn with_performance(mut self, gain: f64, memory_eff: f64) -> Self {
self.performance_gain = gain;
self.memory_efficiency = memory_eff;
self
}
pub fn with_devices(mut self, devices: Vec<String>) -> Self {
self.device_compatibility = devices;
self
}
pub fn with_execution_time(mut self, time: Duration) -> Self {
self.total_execution_time = time;
self
}
pub fn generate_report(&self) -> String {
format!(
"Hybrid F32 Experiment Results:\n\
- Performance Gain: {:.2}%\n\
- Memory Efficiency: {:.2}%\n\
- Accuracy Maintained: {}\n\
- Compatible Devices: {}\n\
- Total Execution Time: {:.2}s\n\
- Conversion Cost Reduction: {:.2}%\n",
self.performance_gain * 100.0,
self.memory_efficiency * 100.0,
if self.accuracy_maintained {
"Yes"
} else {
"No"
},
self.device_compatibility.join(", "),
self.total_execution_time.as_secs_f64(),
self.conversion_cost_reduction * 100.0
)
}
}
impl Default for ExperimentResults {
fn default() -> Self {
Self::new()
}
}
pub struct ExperimentResultsBuilder {
results: ExperimentResults,
}
impl ExperimentResultsBuilder {
pub fn new() -> Self {
Self {
results: ExperimentResults::new(),
}
}
pub fn performance_gain(mut self, gain: f64) -> Self {
self.results.performance_gain = gain;
self
}
pub fn memory_efficiency(mut self, efficiency: f64) -> Self {
self.results.memory_efficiency = efficiency;
self
}
pub fn accuracy_maintained(mut self, maintained: bool) -> Self {
self.results.accuracy_maintained = maintained;
self
}
pub fn add_device(mut self, device: String) -> Self {
self.results.device_compatibility.push(device);
self
}
pub fn execution_time(mut self, time: Duration) -> Self {
self.results.total_execution_time = time;
self
}
pub fn conversion_cost_reduction(mut self, reduction: f64) -> Self {
self.results.conversion_cost_reduction = reduction;
self
}
pub fn build(self) -> ExperimentResults {
self.results
}
}
impl Default for ExperimentResultsBuilder {
fn default() -> Self {
Self::new()
}
}